2012-02-07 14 views
8

Próbuję zmienić źródła danych wielu raportów SSRS z Powershell na jedno udostępnione źródło danych na moim serwerze raportowania. Oto mój kod:Zmiana źródła danych raportu SSRS z Powershell

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 "------------------------" 
} 

Ale ja otrzymuję następujący błąd podczas wywoływania „SetItemDataSources” metoda:

***Argument "1" having the value "ReportingWebService.DataSource[]" of "SetItemDataSources" can not be converted to type "ReportingWebService.DataSource[]".*** 

Pytanie brzmi: Co się stało? Rodzaje to SAME!

Odpowiedz

12

Dzięki e82.eric!

doprowadziłeś mnie do rozwiązania roboczego. Oto ona:

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 "------------------------" 
      } 
+0

Czy możesz mi pomóc w tej sprawie http://stackoverflow.com/questions/41824616/ssrs-setitemdatasource-give-exception – Learner

10

Miałem ten sam problem.

To nie jest świetne rozwiązanie, ale według http://www.vistax64.com/powershell/273120-bug-when-using-namespace-parameter-new-webserviceproxy.html. Parametr przestrzeni nazw New-WebServiceProxy jest nieco uszkodzony. Post sugeruje użycie wygenerowanej automatycznie przestrzeni nazw, która skończyła się dla mnie, więc myślę, że możesz to zrobić.

$reportserver = "myServer" 
$url = "http://$($reportserver)/reportserver/reportservice2005.asmx?WSDL" 
$ssrs = New-WebServiceProxy -uri $url -UseDefaultCredential 

$proxyNamespace = $ssrs.GetType().Namespace 

$myDataSource = New-Object ("$proxyNamespace.DataSource") 
$myDataSource[0].Name = "myDS" 
$myDataSource[0].Item = New-Object ("$proxyNamespace.DataSourceReference") 
$myDataSource[0].Item.Reference = "/Data Sources/MyDS" 

$reports = $ssrs.ListChildren('/DH', $false) 

$reports | ForEach-Object { 
$reportPath = $.path 
Write-Host "Report: " $reportPath 
$dataSources = $ssrs.GetItemDataSources($reportPath) 
$dataSources | ForEach-Object { 
Write-Host "Old source: $($.Name), $($.Item.ConnectString)" 
$ssrs.SetItemDataSources($reportPath, @($myDataSource)) 
Write-Host "New source: $($.Name), $($_.Item.ConnectString)" 
} 

Write-Host "------------------------" } 
+0

Dobry pomysł! teraz błąd jest inny: "Nie można znaleźć źródła danych" myDS "". To dziwne - wiem, że to źródło danych istnieje! :( – eghetto

+0

Dzięki e82.eric pisał roztwór roboczy poniżej: – eghetto

+0

otrzymuję błąd: właściwość „name” nie można znaleźć na tym obiekcie; upewnić się, że istnieje i jest ustawiane $ myDataSource jest Microsoft.PowerShell.Commands!.. NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1NG_ReportService2005_asmx_WSDL.DataSource ja myślę $ myDataSource.Name. – Kiquenet

4
+1

dowolna wersja bez użycia Sharepoint, tylko SSRS? Dla mnie nie działa w "get-spweb" – Kiquenet

+0

IvanJ dzięki za skrypty.On ocalił mi boczek i opracował reat. @Kiquenet Upewnij się, że uruchamiasz to ze powłoki zarządzania SharePoint lub masz zainstalowane przystawienie PowerShell SharePoint. – HAL9256

+0

Wystąpienie błędu poniżej SP2013 "Wywołanie wyjątku" GetItemDataSources "z argumentami" 1 ":" Uprawnienia przyznane użytkownikowi "ZARZĄDZANIE NT \ LOGOWANIE ANONIMOWE" są niewystarczające do wykonania tej operacji. ---> " –

Powiązane problemy