简体   繁体   English

使用 Powershell 批量更改 SSRS 数据源

[英]Bulk Change SSRS Data Sources using Powershell

I'm trying to alter a data source for a set of Reporting Services reports, but I can't get the Powershell to work for them.我正在尝试更改一组 Reporting Services 报告的数据源,但我无法让 Powershell 为它们工作。 I'd appreciate any help:)我会很感激任何帮助:)

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

I wrote a function to do what you are talking about for setting data sources. 我写了一个函数来做你正在谈论的设置数据源。 Here is what I have... Unfortunately I don't have a SSRS instance any longer. 这是我的...不幸的是我不再有SSRS实例了。 The full script / module is on a gist on my GitHub account. 完整的脚本/模块是我的GitHub帐户的要点。 I'll paste my gist urls at the bottom on this thread. 我会在这个帖子的底部粘贴我的主要网址。

The function that I'm pulling the snippet out of is called Deploy-NativeSSRS. 我将代码片段拉出的功能称为Deploy-NativeSSRS。 I used this module + a driver script to push items that had been checked out of TFS. 我使用这个模块+一个驱动程序脚本来推送已经检出TFS的项目。 So they could in turn be parsed and then pushed to SSRS during CI activities. 因此,他们可以在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 https://gist.github.com/crshnbrn66/40c6be436e7c2e69b4de5cd625ce0902 https://gist.github.com/crshnbrn66/b10e43ef0dadf7f4eeae620428b2cdd9

Here something that works with Power BI Report Server Rest API:这是与 Power BI 报表服务器 Rest API 一起使用的东西:

[string] $uri = "https://xxx/Reports"
$session = New-RsRestSession -ReportPortalUri $uri
$reports = Get-RsRestFolderContent -WebSession $session -RsFolder / -Recurse | Where-Object {$_.Type -eq "PowerBIReport"}
 
 
$reports | ForEach-Object {
$dataSources = Get-RsRestItemDataSource -WebSession $session -RsItem $_.Path | Where-Object {$_.ConnectionString -eq "yyy;zzz"}
#$dataSources[0].DataModelDataSource.AuthType = 'Windows'
$dataSources[0].DataModelDataSource.Username = 'domain\user'
$dataSources[0].DataModelDataSource.Secret = 'password'
Set-RsRestItemDataSource -WebSession $session -RsItem $_.Path -RsItemType 'PowerBIReport' -DataSources $dataSources
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM