I'm trying to ahange data sources of multiple SSRS Report with Powershell to one shared data source on my reporting server. Here my code:
cls;
$reportserver = "myServer";<br/>
$url = "http://$($reportserver)/reportserver/reportservice2005.asmx?WSDL";";<br/>
$ssrs = New-WebServiceProxy -uri $url -UseDefaultCredential -Namespace "ReportingWebService";
[ReportingWebService.DataSource[]] $myDataSource = new-object ReportingWebService.DataSource
$myDataSource[0].Name = "myDS"";<br/>
$myDataSource[0].Item = New-Object ReportingWebService.DataSourceReference<br/>
$myDataSource[0].Item.Reference = "/Data Sources/MyDS"<br/>
$reports = $ssrs.ListChildren('/DH', $false)
$reports | ForEach-Object {<br/>
$reportPath = $_.path<br/>
Write-Host "Report: " $reportPath<br/>
$dataSources = $ssrs.GetItemDataSources($reportPath)<br/>
$dataSources | ForEach-Object {<br/>
Write-Host "Old source: $($_.Name), $($_.Item.ConnectString)"<br/>
$ssrs.SetItemDataSources($reportPath, $myDataSource)<br/>
Write-Host "New source: $($_.Name), $($_.Item.ConnectString)"<br/>
}<br/>
Write-Host "------------------------"
}
But I'm getting the following error when calling "SetItemDataSources"-method:
***Argument "1" having the value "ReportingWebService.DataSource[]" of "SetItemDataSources" can not be converted to type "ReportingWebService.DataSource[]".***
The question is: What's wrong? The types are the SAME!
Thanks e82.eric!
you led me to the working solution. Here it is:
cls;
#Set variables:
$reportserver = "myServer";
$newDataSourcePath = "/Data Sources/MyDS"
$newDataSourceName = "MyDS";
$reportFolderPath = "/DH"
#------------------------------------------------------------------------
$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 "------------------------"
}