• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 135
  • Last Modified:

How can I get PowerShell to obtain the ValidValues for a query based parameter in a SSRS report?

Hi experts!

I'm using PowerShell to render SSRS reports. The report I'm trying to render has a parameter that is dependent on the value(s) selected from the first parameter. I'm trying to obtain the valid values for this parameter. Is there a way to do this please? This is the code I have so far:

# add assembly
Add-Type -AssemblyName "Microsoft.ReportViewer.WinForms, Version=, Culture=neutral, PublicKeyToken=89845dcd8080cc91"

# create timestamped folder
# where we will save our report
$dt = Get-Date -Format "yyyy-MMM-dd hhmmtt"
$baseFolder = "\\Folder1\"
$tempfolder = "\\Folder1\Excel files\"

# if the path exists, will error silently and continue
New-Item -ItemType Directory -Path $baseFolder -ErrorAction SilentlyContinue | Out-Null

$ReportServerUri = "http://ServerName/ReportServer//ReportService2005.asmx?wsdl"
$global:proxy = New-WebServiceProxy -Uri $ReportServerUri  -UseDefaultCredential;
$items = $global:proxy.ListChildren("/", $true) |
         Where-Object {$_.Path -like "/ReportFolder/*"};

ForEach ($i in $items){
# report Server Properties
$rv = New-Object Microsoft.Reporting.WinForms.ReportViewer
$rv.ServerReport.ReportServerUrl = "http://ServerName/ReportServer
$rv.ServerReport.ReportPath = $i.Path
$ReportName = $i.Name
$rv.ProcessingMode = "Remote"

$rv.ServerReport.GetParameters()| Where-Object {$_.Name -eq "P_Reg"}|
ForEach-Object {
    $param = $_
    $validValues1 = ""
    $validValues3 = ""
    if ($param.ValidValues -ne $null)
        $validValues1 = [string]::Join(",", ($param.ValidValues[-1..-1] |
                       ForEach-Object {$_.Value}))
      $validValues3 = $param.ValidValues[-1..-1] |
                       ForEach-Object {$_.Value}

$rv.ServerReport.GetParameters()| Where-Object {$_.Name -eq "P_Qual"}
Helen Ramsden
Helen Ramsden
  • 2
1 Solution
lcohanDatabase AnalystCommented:
“You cannot use a Microsoft Visual Basic For Each construct to step through the collection. You need to know the name of a parameter defined in a report definition before you can reference it in your code.”


You will not be able to loop through the Parameters collection.

Alternatively you can try get the parameters list from the Reportserver database and loop through it to get the values of the parameters by using some custom code like:

lcohanDatabase AnalystCommented:
I believe the solution provided is accurate as described in my comment.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now