我尝试更改一组Reporting Services报告的数据源,但我无法让Powershell为他们工作。我很感激任何帮助:)
$server = "http://My/ReportServer/"
$dataSource = Get-RsDataSource -Path "/Data Sources/NewDataSource" -
ReportServerUri $server
$reports = Get-RsCatalogItems -RsFolder "/Testing/NewDataSOurce" -ReportServerUri $server -Recurse | Where-Object {$_.TypeName -eq "Report"}
$reports | ForEach-Object {
$reportDataSource = Get-RsItemDataSource -RsItem $_.Path -ReportServerUri $server
$reportPath = $_.Path
if ($reportDataSource.Name -eq "OldDataSource") {
Set-RsItemDataSource -RsItem $reportPath -DataSource $dataSource -ReportServerUri $server
}
}
答案 0 :(得分:1)
我写了一个函数来做你正在谈论的设置数据源。这是我的...不幸的是我不再有SSRS实例了。完整的脚本/模块是我的GitHub帐户的要点。我会在这个帖子的底部粘贴我的主要网址。
我将片段拉出的功能称为Deploy-NativeSSRS。我使用这个模块+一个驱动程序脚本来推送已经检出TFS的项目。因此,他们可以在CI活动期间进行解析,然后推送到SSRS。
$reports = New-ReportObject -files (Get-ChildItem -Path $reportPath -Filter $reportExtension)
foreach($report in (($reports | Where-Object{$_.datasourcename -eq $datasourceName}).filename))
{
$fileExt = $reportExtension.trim('*')
$status = Set-SSRSDataSourceInfoNative -ReportName ($report.trim($fileext)) -reportPath $documentLibrary -DataSourceName $datasourceName -DataSourcePath "$dataSourceTarget/$datasourceName" -reportWebService $webservice
write-output "The following $report datasource was updated to $datasourcename"
}
function set-SSRSDataSourceInfoNative
{
param
(
[parameter(mandatory)]
[string]$Reportname, #with no extension SSRS has no name for the file in native mode
[parameter(mandatory)]
[string]$reportPath,
[parameter(mandatory)]
[string]$DataSourceName,
[parameter(mandatory)]
[string]$DataSourcePath,
[parameter(mandatory)]
[uri]$reportWebService,
[System.Management.Automation.PSCredential]$Credentials
)
if ($Credentials)
{$reportProxy = new-webserviceproxy -uri $reportWebService -Credential $credentials -namespace 'SSRSProxy' -class 'ReportService2010'}
else
{$reportProxy = new-webserviceproxy -uri $reportWebService -UseDefaultCredential -namespace 'SSRSProxy' -class 'ReportService2010'}
$f = $ReportName.ToLower()
try
{
$dataSources = $reportProxy.GetItemDataSources("$reportpath/$reportname")
}
catch
{
"Error was $_"
$line = $_.InvocationInfo.ScriptLineNumber
"Error was in Line $line"
"ReportName: $reportname"
"ReportPath: $reportpath"
}
$proxyNameSpace = $dataSources.gettype().Namespace
$dc = $reportProxy.GetDataSourceContents($DataSourcePath)
if ($dc)
{
$d = $dataSources | Where-Object {$_.name -like $DataSourceName }
$newDataSource = New-Object ("$proxyNameSpace.DataSource")
$newDataSource.Name = $datasourcename
$newDataSource.Item = New-Object ("$proxyNamespace.DataSourceReference")
$newDataSource.Item.Reference = $DatasourcePath
$d.item = $newDataSource.item
$reportProxy.SetItemDataSources("$reportpath/$f", $d)
$set = ($reportproxy.GetItemDataSources("$reportPath/$f")).name
write-verbose "$reportname set to data source $set"
$returnobj = 'success'
}
$returnobj
}
https://gist.github.com/crshnbrn66/40c6be436e7c2e69b4de5cd625ce0902 https://gist.github.com/crshnbrn66/b10e43ef0dadf7f4eeae620428b2cdd9