Printing from PowerShell

PowerShell has a slick feature that allows you to send the output from a cmdlet or expression directly to a printer. Pipe the output to the Out-Printer cmdlet and it will print out on the default printer:

get-process | out-printer

If you have other printers installed you can use the printer name. For example, I have Adobe Acrobat installed which installs a virtual printer. I can send the output of a command to that printer and generate a pdf:

get-service |where {$_.status -eq “stopped”} |out-printer “Adobe PDF”

If you want to print to a network printer, specify the printer UNC:

get-service |where {$_.status -eq “stopped”} |out-printer “\\Print01\HPLaserJ”

(By the way, you don’t have to wrap the printer name in quotes, but I find it a good practice to avoid any confusion, especially when the printer name might have quotes.)

This is also a quick way to print the contents of text files directly from within PowerShell:

get-content c:\boot.ini |out-printer “\\Print01\hplaserj”

There’s no page numbering or formatting options but it is a quick way to get a hard copy of you results.

Technorati Tags: