Render SSRS Report with parameters using SOAP in Powershell

前端 未结 3 1415
别那么骄傲
别那么骄傲 2021-01-03 08:23

I\'ve been toying with this for days with no luck. Essentially I\'m trying to build a simple library to render SSRS reports using Powershell. I\'m using Powershell in an a

3条回答
  •  清酒与你
    2021-01-03 08:57

    I had a similar issue. It took time to figure out the issue. You should not "revoke" the report without parameters if needed Therefore the code should look like this:

    try {
        <# Despose and clear resources if open #>
        if ($RS) { $RS.Dispose() }
        if ($Stream) { $Stream.Close() }
    
        <# Create Report Service #>
        [string]$reportServerURI = ""
        $RS = New-WebServiceProxy -Class 'RS' -NameSpace 'RS' -Uri $reportServerURI -UseDefaultCredential
        $RS.Url = $reportServerURI
        <# Set up some variables to hold referenced results from Render #>
        $deviceInfo = "True"
        $extension = ""
        $mimeType = ""
        $encoding = ""
        $warnings = $null
        $streamIDs = $null
    
        <# Initial Report #>
        $reportPath = ""
        ## Do not revoke the report ## $Report = $RS.GetType().GetMethod("LoadReport").Invoke($RS, @($reportPath, $null))
        <# Initial Report Parameters Array #> 
        $Parameters = $RS.GetType().GetMethod("LoadReport").Invoke($RS, @($reportPath, $null)).Parameters
        
        <# Populate Report Parameters values #>
        $Params = @()
        Foreach ($Parameter in $Parameters ) {
            $par1 = New-Object RS.ParameterValue;
            $Par1.Name = $Parameter.Name;
            $Par1.Label = $Parameter.Name;
            switch ($Par1.Name) {
                    "<1st Param Name>"      { $par1.Value = <1st Param Value>; break }
                    "<2nd Param Name>"      { $par1.Value = <2nd Param Value>; break }
                    ...
                    "<#n Param Name>"      { $par1.Value = <#n Param Value>; break }
                }
            $Params += $Par1;
            }
    
        <# Execute/invoke the report with the parameters #>
        $RS.SetExecutionParameters($Params, "en-us") > $null
        
        <# Set report render output format#>
        [string]$format = <"PDF","Excel" etc.>
    
        <# Eecute Report render #>
        try { $RenderOutput = $RS.Render($format,
        $deviceInfo,
        [ref] $extension,
        [ref] $mimeType,
        [ref] $encoding,
        [ref] $warnings,
        [ref] $streamIDs)       
        } catch { Log-Message -message "Unable to render or save the report due to an error." -IsError $true; throw
        }
        
        <# Convert array bytes to file and write #>
        $Stream = New-Object System.IO.FileStream(

    Problem solved.

提交回复
热议问题