question

thayle avatar image
thayle asked

Change DataSource of SSRS Report with Powershell

Starting with the answer from another question like this which works to set all the reports to the same Data Source. I need to see the reports data source reference and set the data Source to the same value as the reference defined in the report. How can I dynamically pick up the report reference and assign it as the data source Item in the forEach-Object loop instead of using the static Data Source parameter value? This code picked up from the previous answer works to assign a single Data Source to all the reports in the list. cls; #Set variables: $reportserver = "thayletestvm1:80"; $url = "http://$($reportserver)/reportserver/reportservice2005.asmx?WSDL"; $newDataSourcePath = "/Data Sources/CPC"; $newDataSourceName = "CPC"; $reportFolderPath = "/Rprl/1000 Transactions/1100 Daily By Toll Day"; #------------------------------------------------------------------------ $ssrs = New-WebServiceProxy -uri $url -UseDefaultCredential $reports = $ssrs.ListChildren($reportFolderPath, $false) $reports | ForEach-Object { $reportPath = $_.path Write-Host "Report: " $reportPath $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 "Report's DataSource Reference ($($_.Name)): $($_.Item.Reference)"; } Write-Host "------------------------" }
powershelldynamicreporting_servicesdatasource
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

0 Answers

· Write an Answer

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.