SSRS PowerShell无法转换参数

时间:2017-01-30 23:05:56

标签: powershell reporting-services

我们有区域化的SSRS服务器,我正在尝试创建一个PowerShell脚本,用于将项目从一个SSRS服务器复制到其他服务器,以使它们保持同步。对于某些项目,这是有问题的。一个例子是系统策略(通过系统权限复制)。

最初我试过了:

#Reference source SSRS instance
$SourceServer = "Source Server Name"
$sourceServerUrl = "http://" + $SourceServer + "/ReportServer/ReportService2010.asmx"
$SourceProxy = New-WebServiceProxy -Uri $sourceServerUrl -Namespace SSRS.ReportingService2010 -UseDefaultCredential

#Reference target SSRS instance
$DestinationServer = "Target Server Name"
$TargetServerUrl = "http://" + $DestinationServer + "/ReportServer/ReportService2010.asmx"
$TargetProxy = New-WebServiceProxy -Uri $TargetServerUrl -Namespace SSRS.ReportingService2010 -UseDefaultCredential


#Compare System Policies
$SourceSystemPolicies = $SourceProxy.GetSystemPolicies()
$TargetSystemPolicies = $TargetProxy.GetSystemPolicies()

If ($SourceSystemPolicies -ne $TargetSystemPolicies) {
    $TargetProxy.SetSystemPolicies($SourceSystemPolicies)
}

当我在新服务器上尝试SetSystemPolicies时,我收到错误

Cannot convert argument "Policies", with value: "SSRS.ReportingService2010.Policy[]", for "SetSystemPolicies" to type "SSRS.ReportingService2010.Policy[]": "Cannot convert the "SSRS.ReportingService2010.Policy" value of type 
"SSRS.ReportingService2010.Policy" to type "SSRS.ReportingService2010.Policy"."

在查找问题后,我发现PowerShell尝试使用默认名称空间而不是SSRS命名空间是名称空间问题。我更新了我的代码以创建一个仍然无效的自定义命名空间。

#Reference source SSRS instance
$SourceServer = "Source Server Name"
$sourceServerUrl = "http://" + $SourceServer + "/ReportServer/ReportService2010.asmx"
$SourceProxy = New-WebServiceProxy -Class 'RS' -NameSpace 'RS' -Uri $sourceServerUrl -UseDefaultCredential

#Reference target SSRS instance
$DestinationServer = "Target Server Name"
$TargetServerUrl = "http://" + $DestinationServer + "/ReportServer/ReportService2010.asmx"
$TargetProxy = New-WebServiceProxy -Class 'RS' -NameSpace 'RS' -Uri $TargetServerUrl -UseDefaultCredential

#Compare System Policies
$SourceSystemPolicies = $SourceProxy.GetSystemPolicies()
$TargetSystemPolicies = $TargetProxy.GetSystemPolicies()
[RS.Policy[]] $SystemPolicyArray = @()

If ($SourceSystemPolicies -ne $TargetSystemPolicies) {
    $PolicyCounter = 0
    ForEach ($SourceSystemPolicy in $SourceSystemPolicies) {
        $SystemPolicyArray += New-Object RS.Policy
        $SystemPolicyArray[$PolicyCounter].GroupUserName = $SourceSystemPolicy.GroupUserName
        $SystemPolicyArray[$PolicyCounter].Roles = $SourceSystemPolicy.Roles
        $PolicyCounter += 1
    }

    $TargetProxy.SetSystemPolicies($SystemPolicyArray)
}

新错误

Cannot convert argument "Policies", with value: "RS.Policy[]", for "SetSystemPolicies" to type "RS.Policy[]": "Cannot convert the "RS.Policy" value of type "RS.Policy" to type "RS.Policy"."

我还尝试使用GetType()动态创建命名空间。命名空间没有成功。

1 个答案:

答案 0 :(得分:0)

原来我错误地自动化了这个。我试图用正确的命名空间创建一个新对象,并直接为旧对象分配,而不是分配单个属性。最终的解决方案是:

#!/usr/bin/env bash
#
# Install JUST the required dependencies for the project.
# May be used for ci or other team members.
#

for I in android-25 \
         build-tools-25.0.2  \
         tool \
         extra-android-m2repository \
         extra-android-support \
         extra-google-google_play_services \
         extra-google-m2repository;

 do echo y | android update sdk --no-ui --all --filter $I ; done