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
36 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 39

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 39

Expert Comment

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now