Skip to content

Instantly share code, notes, and snippets.

@ghotz
Last active March 27, 2020 15:48
Show Gist options
  • Select an option

  • Save ghotz/d17d5abf68fbd9ff9dbca51f52006505 to your computer and use it in GitHub Desktop.

Select an option

Save ghotz/d17d5abf68fbd9ff9dbca51f52006505 to your computer and use it in GitHub Desktop.
Dump Reporting Services Data Sources used in all reports to CSV
# Install-Module ReportingServicesTools; # https://github.com/microsoft/ReportingServicesTools
Import-Module ReportingServicesTools;
$rsServerName = "localhost";
$rsAllContent = Get-RsFolderContent -RsFolder "/" -ReportServerUri "http://$rsServerName/ReportServer" -Recurse;
$rsAllReports = $rsAllContent | ? { $_.TypeName -eq "Report" } #| Select * -First 5;
$rsAllReports | % {
$ReportName = $_.Path;
$rsAllReportsDS = Get-RsItemDataSource -RsItem $_.Path -ReportServerUri "http://$rsServerName/ReportServer";
$rsAllReportsDS | % {
$CSVLine = New-Object System.Object;
$CSVLine | Add-Member -MemberType NoteProperty -Name ReportPath -Value $ReportName;
$CSVLine | Add-Member -MemberType NoteProperty -Name DataSourceType -Value $_.Item.GetType().Name;
$CSVLine | Add-Member -MemberType NoteProperty -Name Reference -Value $_.Item.Reference;
$CSVLine | Add-Member -MemberType NoteProperty -Name DataSource -Value $_.Item.ConnectString;
$CSVLine | Add-Member -MemberType NoteProperty -Name UserName -Value $_.Item.UserName;
$CSVLine | Add-Member -MemberType NoteProperty -Name Password -Value $_.Item.Password;
};
$CSVLine;
} | Export-Csv -Path "$rsServerName-datasources.csv" -NoTypeInformation;
' Dump Reporting Services data sources to CSV
'
' Use with rs.exe for example
' C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn
' rs.exe" -i dump_datasources.rss -s http://localhost/reportserver -e Mgmt2010
'
' https://docs.microsoft.com/en-us/sql/reporting-services/tools/rs-exe-utility-ssrs
' References https://docs.microsoft.com/en-us/dotnet/api/reportservice2010.reportingservice2010
' https://github.com/microsoft/sql-server-samples/blob/master/samples/features/reporting-services/ssrs-migration-rss/ssrs_migration.rss
Public Sub Main()
Try
Dim items As CatalogItem() = Nothing
items = rs.ListChildren("/", True)
Console.WriteLine("Report, DataSourceType, DataSource")
For Each item As CatalogItem In items
If item.TypeName = "Report" Then
Dim srcCSVLine As String = item.Path + ","
Dim srcDataSources As DataSource() = rs.GetItemDataSources(item.Path)
If srcDataSources Is Nothing Then
srcCSVLine = srcCSVLine + ","
Else
For Each srcDS As DataSource In srcDataSources
If TypeOf srcDS.Item Is DataSourceReference
Dim srcDSRef As DataSourceReference = srcDS.Item
srcCSVLine = srcCSVLine + "Shared," + srcDSRef.Reference
ElseIf TypeOf srcDS.Item Is DataSourceDefinition Then
Dim srcDSDef As DataSourceDefinition = srcDS.Item
srcCSVLine = srcCSVLine + "Defined," + srcDSDef.ConnectString
End If
Next
End If
Console.WriteLine(srcCSVLine)
End If
Next
Catch e As Exception
Console.WriteLine(e.Message)
End Try
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment