Solved

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

Posted on 2016-08-24
2
68 Views
Last Modified: 2016-09-19
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=12.0.0.0, 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"}
}
0
Comment
Question by:Helen Ramsden
  • 2
2 Comments
 
LVL 40

Accepted Solution

by:
lcohan earned 500 total points (awarded by participants)
ID: 41774907
“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.”

http://blogs.msdn.com/b/jenss/archive/2008/04/30/enumerating-parameter-collection-in-sql-server-reporting-services.aspx

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:

https://gallery.technet.microsoft.com/scriptcenter/SSRS-Custom-code-to-f73d610d
0
 
LVL 40

Expert Comment

by:lcohan
ID: 41804471
I believe the solution provided is accurate as described in my comment.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question