【问题标题】:Change DataSource of SSRS Report with Powershell使用 Powershell 更改 SSRS 报表的数据源
【发布时间】:2012-02-29 00:35:01
【问题描述】:

我正在尝试将使用 Powershell 的多个 SSRS 报告的数据源更改为我的报告服务器上的一个共享数据源。这是我的代码:

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

但调用“SetItemDataSources”方法时出现以下错误:

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

问题是:怎么了?类型相同!

【问题讨论】:

    标签: powershell datasource reportingservices-2005


    【解决方案1】:

    【讨论】:

    • 任何不使用 Sharepoint 的版本,只有 SSRS ?对我来说,“get-spweb”失败了。
    • IvanJ 感谢脚本。它救了我的培根,效果很好。 @Kiquenet 确保您从 SharePoint 命令行管理程序运行它,或者安装了 SharePoint PowerShell 管理单元。
    • SP2013 出现以下错误“使用“1”参数调用“GetItemDataSources”的异常:“授予用户“NT AUTHORITY\ANONYMOUS LOGON”的权限不足以执行此操作。 --->"
    • 据我所知,sharepoint 的东西不存在,或者无法再安装(Windows 10)
    【解决方案2】:

    感谢 e82.eric!

    你让我找到了可行的解决方案。这里是:

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

    【讨论】:

    【解决方案3】:

    我遇到了同样的问题。

    这不是一个很好的解决方案,但根据http://www.vistax64.com/powershell/273120-bug-when-using-namespace-parameter-new-webserviceproxy.html。 New-WebServiceProxy 的命名空间参数有些损坏。该帖子建议使用最终为我工作的自动生成的名称空间,所以我认为您可以这样做。

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

    【讨论】:

    • 好主意!现在错误不同了:“找不到数据源'myDS'”。很奇怪——我知道这个数据源确实存在! :(
    • 我收到错误:在此对象上找不到属性“名称”;确保它存在并且是可设置的。 $myDataSource 是 Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1NG_ReportService2005_asmx_WSDL.DataSource 我认为是 $myDataSource.Name。
    • 您使用的是什么版本的 ssrs?是原生模式还是共享点?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多