Question

Can I use a Powershell to generate and print an SSRS report (with parameters) to a network printer.

I will use a SQL Agent job poll a table for new order entries. When an order comes in I want to generate an SSRS report and print it to one of many remote printers (printer will be one of the input parameters) on our network, e.g., print a pick ticket in the appropriate warehouse when an order is placed.

We currently use batch files to print to local printers, but the program hangs often and does not scale well.

Was it helpful?

Solution

In this case:
Report Name: Ticket System
Parameters are: Date and Department
Report Format:PDF

#Place adobe in your path
$env:Path = $env:Path + ";C:\Program Files (x86)\Adobe\Reader 11.0\Reader"

#Specify variables and pass parameters and specify format of report PDF (to keep things simple)
$url = "http://$serverName/ReportServer?/$reportFolder/Ticket+System&Date=3-31-2014&Department=Finance&rs:Format=PDF"

#Use alternative credentials as needed to access report server
$webclient = New-Object System.Net.WebClient
$webclient.UseDefaultCredentials = $TRUE

$file = "C:\temp\report.pdf"
$webclient.DownloadFile($url,$file)

#Specify printer \\server\name
$printer = "\\NorthSide\SharpPrinter"

#The /s /o switch may not be necessary. You can test it out.
AcroRd32.exe /s /o /t $file $printer

Get-Process AcroRd32.exe | kill

References: This link will indicate how to pass parameters to a report via url http://msdn.microsoft.com/en-us/library/ms155391.aspx

This link will indicate how to access a report in a printable format via url http://msdn.microsoft.com/en-us/library/ms154040.aspx

This link will show you how to use powershell to write this file to the filesystem via url. http://teusje.wordpress.com/2011/02/19/download-file-with-powershell/

This link will show you how to push the job to the spooler. Using Powershell version 4.0 http://technet.microsoft.com/en-us/library/hh849886.aspx

If you are having trouble using powershell in a sql agent job, I alternatively would do the polling with a Task Scheduler job and query your database using the SQLPS module.

Hope that helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top