microsoft / ReportingServicesTools

Reporting Services Powershell Tools
MIT License
458 stars 213 forks source link

Changing an embedded report datasource to a shared datasource #412

Open ArnaudB88 opened 1 year ago

ArnaudB88 commented 1 year ago

Currently it is not possible to change an embedded datasource to a shared datasource reference in an existing report with the Set-RsItemDataSource function. The code I expect to work, doesn't:

$reportServerUrl = "http://hostname/Reportserver"
$dstReportPath = "/Reports/ReportNameFoo"
$dataSourcePath = "/Datasources/DataSourceFoo"

Connect-RsReportServer -ReportServerUri $reportServerUrl -Credential $credential
$proxy = New-RsWebServiceProxy #use default connection

$newDs = New-Object ($proxy.GetType().Namespace + ".DataSource")
$newDs.Name = "NewDs"
$newDs.Item = New-Object($proxy.GetType().Namespace + ".DataSourceReference")
$newDs.Item.Reference = $dataSourcePath

Set-RsItemDataSource -ReportServerUri $reportServerUrl -RsItem $dstReportPath -DataSource $newDs

This gives the exception Please use Set-RsDataSource to update shared data sources!

The exception is thrown in the file Set-RsItemDataSource.ps1 and is a simple check. I don't know why this check is added, since the exception message doesn't make sense. I want to change the report datasource instead of modifying a shared datasource (which can be done with the suggested function 'Set-RsDataSource')

The bypass I use now is $proxy.SetItemDataSources($dstReportPath, $newDs);

Question: can this check (with throwing the exception) be removed so we can use the function for the above scenario?