简体   繁体   English

如何在PowerShell中为SSRS报告设置正确的数据源

[英]How to set correct DataSource in PowerShell for SSRS reports

I have a PowerShell script that should set the correct data source for a report. 我有一个PowerShell脚本,应该为报表设置正确的数据源。
I have more data sources for example DS1 and DS2. 我有更多的数据源,例如DS1和DS2。

Here is part of my PowerShell code: 这是我的PowerShell代码的一部分:

function UpgradeReport
{
    param
    (
        [string]$t,
        [string]$ReportFolder,
        [string]$ReportName,
        [string]$DataSourceFolder,
        [string]$IssueId
    )

if([string]::IsNullOrEmpty($DataSourceFolder)) { $DataSourceFolder="DS1" }

.......
# if all ok since now, report is uploaded
        # set datasource if new report
        if (!$reports.$reportName) {
            Write-Host $reportName ' is new. Setting data source: ' $DataSourceFolder
            $Proxy.SetItemDataSources("/$reportFolder/$reportName", $datasources.$DataSourceFolder)
        }
        Write-Output "$(Timestamp) Finished InstallReports for $ReportName"

.....

# get list of all datasources
$Proxy.ListChildren('/Data Sources', $false) | ForEach-Object { $datasources.add($_.Name,$_ ) }

The problem is probably in SetItemDataSources where I have $datasources.$DataSourceFolder 问题可能SetItemDataSources在我有$datasources.$DataSourceFolder SetItemDataSources

If someone knows how I can fix this I will be happy. 如果有人知道我该如何解决,我会很高兴。

I am using primarily SSRS 2008 but I am sure your issue is that the overload for SetItemDataSources is looking for a DataSource object . 我主要使用SSRS 2008,但是我确定您的问题是SetItemDataSources重载正在寻找DataSource对象 Not just a path to the object. 不只是对象的路径。

$newDataSource = New-Object "$ssrsServiceNamespace.DataSource"
$newDataSource.Name = $DataSourceName
$newDataSource.Item = New-Object ("$ssrsServiceNamespace.DataSourceReference")
$newDataSource.Item.Reference = $DataSourcePath
Write-Verbose "New Datasource Name     : $($newDataSource.Name)"
Write-Verbose "New Datasource Reference: $($newDataSource.Reference)"

$ReportService.SetItemDataSources($reportPath, $newDataSource)

Notes about the above code: 有关上述代码的注意事项:

$ssrsServiceNamespace.DataSource comes from the connection object. $ssrsServiceNamespace.DataSource来自连接对象。 It creates an instance specific DataSource object. 它创建一个实例特定的DataSource对象。 For me, making a generic one ended up with type conversion errors causing SetItemDataSources() to fail. 对我来说,制作一个通用类最终会导致类型转换错误,从而导致SetItemDataSources()失败。 $ReportService.Gettype().Namespace . $ReportService.Gettype().Namespace So for me that works out to Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1tServer_ReportService2005_asmx and my way look nicer and theoretically helps my code be more portable between SSRS environments. 因此,对我来说,它适用于Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1tServer_ReportService2005_asmx而且我的方法看起来更好,并且理论上可以帮助我的代码在SSRS环境之间更易于移植。

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

相关问题 SSRS&PowerShell:创建并设置报告时间表吗? - SSRS & PowerShell: Create and set schedule for reports? 使用Powershell更改SSRS报告的数据源 - Change DataSource of SSRS Report with Powershell 上传之前先在Powershell中更新SSRS数据源参考 - Update SSRS Datasource Reference in Powershell before Upload 使用PowerShell在客户的计算机上部署SSRS报告 - Deploy SSRS reports on a customer's machine with PowerShell 将SharePoint库中的所有SSRS报表连接到共享数据源 - Connect all SSRS Reports in SharePoint library to Shared DataSource 使用 powershell 从 SQL 服务器报告服务 (SSRS) 自动获取报告 - Get reports automatically from SQL Server Reportings Services (SSRS) with powershell 如何使用Powershell将带有数据源的ComboBox的DispayMember和ValueMember属性设置为对象? - How do I set the DispayMember and ValueMember Properties of a ComboBox w/ DataSource set to an Object using Powershell? 如何在Powershell中列出直接报告 - How to list a direct reports in Powershell 无法在PowerShell中设置正确的编码 - Unable to set correct encoding in powershell 如何使用 ReportService2010 在 PowerShell 中将 SSRS 报告的隐藏属性设置为“True”? - How do I set a SSRS report's Hidden property to “True” in PowerShell using ReportService2010?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM