I have a PowerShell script that should set the correct data source for a report.
I have more data sources for example DS1 and DS2.
Here is part of my PowerShell code:
function UpgradeReport
{
param
(
[string]$t,
[string]$ReportFolder,
[string]$ReportName,
[string]$DataSourceFolder,
[string]$IssueId
)
if([string]::IsNullOrEmpty($DataSourceFolder)) { $DataSourceFolder="DS1" }
.......
# if all ok since now, report is uploaded
# set datasource if new report
if (!$reports.$reportName) {
Write-Host $reportName ' is new. Setting data source: ' $DataSourceFolder
$Proxy.SetItemDataSources("/$reportFolder/$reportName", $datasources.$DataSourceFolder)
}
Write-Output "$(Timestamp) Finished InstallReports for $ReportName"
.....
# get list of all datasources
$Proxy.ListChildren('/Data Sources', $false) | ForEach-Object { $datasources.add($_.Name,$_ ) }
The problem is probably in SetItemDataSources
where I have $datasources.$DataSourceFolder
If someone knows how I can fix this I will be happy.
I am using primarily SSRS 2008 but I am sure your issue is that the overload for
SetItemDataSources
is looking for a DataSource object. Not just a path to the object.Notes about the above code:
$ssrsServiceNamespace.DataSource
comes from the connection object. It creates an instance specific DataSource object. For me, making a generic one ended up with type conversion errors causingSetItemDataSources()
to fail.$ReportService.Gettype().Namespace
. So for me that works out toMicrosoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1tServer_ReportService2005_asmx
and my way look nicer and theoretically helps my code be more portable between SSRS environments.