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
87 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
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…

615 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