Update SSRS Datasources in a directory
- Don Richardson
- Jun 28, 2019
- 1 min read
So you need to update all the datasources on your SSRS server. Well just one directory for now.
UpdateDatasource -TargetURL $targetURL -reportFolderPath $targetDirectory -targetReportServer "<TargetServer>"
and here's the function:
function UpdateDatasource
{
Param ([string] $TargetURL, [string] $reportFolderPath, [string] $targetReportServer)
# Example: UpdateDatasource -TargetURL "http://<TargetReportServer>/reportserver/ReportService2010.asmx?wsdl" -reportFolderPath "/Staging_Miscellaneous" -targetReportServer <TargetServer>
$url = $TargetURL
#Set variables:
$reportserver = $targetReportServer;
$newDataSourcePath = "/Data Sources/<targetdatasource>"
$newDataSourceName = "<targetdatasource>";
$reportFolderPath = $reportFolderPath
#------------------------------------------------------------------------
$ssrs = New-WebServiceProxy -uri $url -UseDefaultCredential
$reports = $ssrs.ListChildren($reportFolderPath, $false)
$reports | ForEach-Object {
$reportPath = $_.path
Write-Host "Update " $reportPath " To: " $newDataSourceName
$dataSources = $ssrs.GetItemDataSources($reportPath)
$dataSources | ForEach-Object {
$proxyNamespace = $_.GetType().Namespace
$myDataSource = New-Object ("$proxyNamespace.DataSource")
$myDataSource.Name = $newDataSourceName
$myDataSource.Item = New-Object ("$proxyNamespace.DataSourceReference")
$myDataSource.Item.Reference = $newDataSourcePath
$_.item = $myDataSource.Item
$ssrs.SetItemDataSources($reportPath, $_)
}
Write-Host "------------------------"
}
}
Comments