Get-Printer

I think Out-Printer is a very handy cmdlet, and one that doesn’t get used much. Pipe any cmdlet to it and the output will be printed to your default printer. You use it the same way you would Out-File except output is printed instead of saved to a file. The cmdlet also has a parameter that lets you specify a  printer. This is very handy if, like me, you have a PDF printer installed. The challenge though is to remember the printer names. To that end I wrote a simple PowerShell script to query the registry and return some basic printer information.

Continue reading

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: