Feeds:
Posts
Comments

Archive for January, 2015

Recently I was asked if you could use PowerShell to print to a specific printer.  I have written posts on how to print to your default printer but had never tried printing to a specific printer.  So I decided I should see if this is possible.

And what do you know there is a built in cmdlet called Out-Printer that accepts the -Name parameter.  Using this optional parameter allows you to specify an alternate printer.

OK so now that I’ve got that lets try it out.  I have a printer here in my office which is an HP 2600 color laserjet printer.  It is NOT my default printer so I would like to test printing to it using that cmdlet.

First lets just test the cmdlet without the optional parameter.

get-process | Out-Printer

Sure enough that prints the get-process output directly to my default printer.

Now lets try

get-process | Out-Printer -name \\Svr1\it-2600n

Sure enough this printed out to the HP 2600 color laser.  PERFECT!!!

Now there are a few problems with this cmdlet, the first being that if you specify the -name parameter and you are trying to print to a shared printer you need to use the UNC name of that printer.

The second problem is that this is a cmdlet that prints output.  It does not print the CONTENT of a file.  So for example if you wanted to print a txt document and you wrote Out-Printer “c:\test.txt” it would actually print out a page with c:\test.txt on it.

You could use the Get-Content cmdlet and pipe that into the Out-Printer cmdlet like this Get-Content “c:\test.txt” | Out-Printer

This would give you a printout of the actual contents of the test.txt file.  However, if you wanted to print a word document or a pdf document this would not work.  It will give you tons of garbage and not the actual file contents.

So you are back to the drawing board again.  To print a word or pdf document you need to use this command.

Start-Process -FilePath “C:\Test.Docx” -Verb Print

Which brings you back to the original issue that was made, how do I print to a printer that isn’t the default one?

And for the moment I have to say I don’t see a way.  I think you need to set the default printer first, then you can use the Start-Process cmdlet and print the document.

Advertisements

Read Full Post »