SSRS和powershell:参数不被接受

ste*_*rgh 10 powershell reporting-services

我使用Powershell在Microsoft SQL Report Services上运行多个报告,并将结果保存到Word文档.我有一个脚本,其中包含处理与Report Server通信的函数:

## File "qrap-functions.ps1"
function GetRSConnection($server, $instance)
{
    $User = "xxxx"
    $PWord = ConvertTo-SecureString -String "yyyy" -AsPlainText -Force
    $c = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord

    $reportServerURI = "http://" + $server + "/" + $instance + "/ReportExecution2005.asmx?WSDL"

    $RS = New-WebServiceProxy -Class 'RS' -NameSpace 'RS' -Uri $reportServerURI -Credential $c
    $RS.Url = $reportServerURI
    return $RS
}
function GetReport($RS, $reportPath)
{
    $reportPath = "/" + $reportPath
    #$reportPath
    $Report = $RS.GetType().GetMethod("LoadReport").Invoke($RS, @($reportPath, $null))      
    $parameters = @()
    $RS.SetExecutionParameters($parameters, "nl-nl") > $null
    return $report
}
function AddParameter($params, $name, $val)
{
    $par = New-Object RS.ParameterValue
    $par.Name = $name
    $par.Value = $val
    $params += $par
    return ,$params
}
function GetReportInFormat($RS, $report, $params, $format, $saveas)
{
    $deviceInfo = "<DeviceInfo><NoHeader>True</NoHeader></DeviceInfo>"
    $extension = ""
    $mimeType = ""
    $encoding = ""
    $warnings = $null
    $streamIDs = $null

    $RS.SetExecutionParameters($params, "nl-nl") > $null

    $RenderOutput = $RS.Render($format,
        $deviceInfo,
        [ref] $extension,
        [ref] $mimeType,
        [ref] $encoding,
        [ref] $warnings,
        [ref] $streamIDs
    )
    $Stream = New-Object System.IO.FileStream($saveas), Create, Write
    $Stream.Write($RenderOutput, 0, $RenderOutput.Length)
    $Stream.Close()
}
Run Code Online (Sandbox Code Playgroud)

然后,我有一个脚本执行包含财务季度数据的报告.这个脚本运行正常:

## File "qrap-financieel.ps1"
. "./qrap-functions.ps1"

$saveas = "e:\test\financieel.doc"
$RS = GetRSConnection -server "MSZRDWH" -instance "reportserver_acc"
$report = GetReport -RS $RS -reportPath "kwartaalrapportage/kwartaalrapportage financieel"
$params = @()   
$kwartaal = "[Periode Maand].[Jaar Kwartaal].&[2015-2]"
$kptc = "[Kostenplaats].[Team code].&[2003]"

$params = AddParameter -params $params -name "PeriodeMaandJaarKwartaal" -val $kwartaal
$params = AddParameter -params $params -name "KostenplaatsTeamcode" -val $kptc

GetReportInformat -RS $RS -report $report -params $params -format "WORD" -saveas $saveas
Run Code Online (Sandbox Code Playgroud)

这里的值$kwartaal$kptc硬编码,但是这个脚本的实际版本中的参数.除了财务季度,我们还有其他三个季度报告需要通过此脚本输出.其中两个运行正常,在第四个我似乎无法获得正确的参数之一.该脚本的脚本是:

## File "qrap-zorglog.ps1"
. "./qrap-functions.ps1"
$RS = GetRSConnection -server "MSZRDWH" -instance "reportserver_acc"
$report = GetReport -RS $RS -reportPath "kwartaalrapportage/kwartaalrapportage zorglogistiek"

$s = "Urologie"
$saveas = "e:\test\ZL Urologie.doc"
$params = @()   
$kwartaal = "[Periode Maand].[Jaar Kwartaal].&[2015-2]" 

$params = AddParameter -params $params -name "HoofdspecialismeSpecialismeOms"                       -val "[Hoofdspecialisme].[Specialisme Oms].&[$s]"
$params = AddParameter -params $params -name "PeriodeMaandJaarKwartaal"                             -val $kwartaal
$params = AddParameter -params $params -name "WachttijdenSpecialismeSpecialisme"                    -val "[Wachttijden Specialisme].[Specialisme].&[$s]"
$params = AddParameter -params $params -name "SpecialisatieGroeperingSpecialisatieGroeperingOms"    -val "[Specialistie Groepering].[Specialistie Groepering Oms].&[$s]"    
$params = AddParameter -params $params -name "AanvragendSpecialismeSpecialismeOms"                  -val "[AanvragendSpecialisme].[Specialisme Oms].&[$s]"

GetReportInformat -RS $RS -report $report -params $params -format "WORD" -saveas $saveas
Run Code Online (Sandbox Code Playgroud)

当我执行此脚本时,我收到此错误:

Exception calling "Render" with "7" argument(s): "System.Web.Services.Protocols.SoapException: This report requires a 
default or user-defined value for the report parameter 'HoofdspecialismeSpecialismeOms'. To run or subscribe to this 
report, you must provide a parameter value. ---> Microsoft.ReportingServices.Diagnostics.Utilities.ReportParameterValueNot
SetException: This report requires a default or user-defined value for the report parameter 
'HoofdspecialismeSpecialismeOms'. To run or subscribe to this report, you must provide a parameter value.
Run Code Online (Sandbox Code Playgroud)

我显然为'HoofdspecialismeSpecialismeOms'提供了一个值; 我之前已经注意到,当参数不是预期的格式时,也会抛出此错误.此格式,因为报表筛选器基于SSAS多维数据集中的层次结构,如下所示:[hierarchy].[sub-level].&[member].[Hoofdspecialisme].[Specialisme Oms].&[$s]通过在填充SSRS中的提示的查询中查找,我确保这是正确的格式.报告在通过SSRS运行时显示数据 - 并从提示中获取参数.

我注意到这个参数允许多个选择.但是,我不相信这会导致错误,因为这也是如此AanvragendSpecialismeSpecialismeOms.

知道为什么这个参数在调用时无法输入报告GetReportInformat

ste*_*rgh 0

我终于弄清楚了:失败的提示启用了多选。当填写多项选择时,SSRS 需要一个值列表。当仅给出一个字符串时,该字符串将被忽略,并且该参数被假定为空白。

为了给它提供一个列表,我们必须这样做:

$multival = New-Object System.Collections.Specialized.StringCollection
$multival.Add("[Hoofdspecialisme].[Specialisme Oms].&[$s]")
[snip]
$params = AddParameter -params $params -name "HoofdspecialismeSpecialismeOms" -val $multival
Run Code Online (Sandbox Code Playgroud)

由于这个问题找到了答案: How to pass multiple value parameter to reporting services report via powershell