How to use PowerShell to install printers

Jordan Hammond fun headshot
Jordan Hammond|June 25, 2020
install printers
install printers

Printers are the honest-to-goodness worst. With this shared knowledge we could collectively take one into an open field with some baseball bats, or we could concentrate on some neat PowerShell in here that will make setting up these demonic devices a little less terrible.

Group Policy first

Before you even look at PowerShell, do you have the option to set this up with Group Policy? If yes, do that. Seriously, you can set up printers to install on devices based on IP range, so if your networking is all tidy, anybody could move a device anywhere in the building, and they will have the closest printer available to them.

PowerShell with a print server

Moving past Group Policy, if you have a print server, it is effortless to do in PowerShell. It is a one-liner.

Add-Printer -ConnectionName \\printserver\printername

Nice and easy. The print server will handle all of the steps. Namely, add the driver to the store, install the driver, create the printer port, and finally install the printer. That is a lot to pack into a single command.

Installing with just PowerShell

Finally, let us take a look at what we need to do when we need to install a printer. It can get a little tricky here, and I will be honest with you, research into this contributed to 87.5%. We will need to manually do the four things we mentioned in the Print Server section. I am assuming that you have gone to the printer vendor and got the drivers you need, and we are just using PowerShell to get them onto machines.

Add driver to the store

Microsoft can't have drivers for every device already in the driver store; there is too much. So it is likely that the printer you have will not already be in the driver store. I use pnputil.exe to do this. I can hear your complaints now! "That is not PowerShell," and "How Dare You!!!!!!". I have just found that this works best for me. I will also run it from PowerShell if that helps. The second roadblock was I was unclear if I could use a UNC path with the command. I can honestly tell you I spent 30 minutes trying to find documentation on this and came up empty. I did find a forum post where a person said they could not find documentation. To get around this, what I did was….try it. Thirty seconds later, and I can confirm pnputil.exe can accept an unc path. Let's take a look at the command.

pnputil.exe /a "\\fileshare\HPPrinter\*.inf"

This command will add the driver to the store at C:\Windows\System32\DriverStore. This example would run against all .inf files in the specified folder. If you know the exact file, it would be easier to add the full name in there.

Install the driver

Pnputil.exe does not install the driver, but it just makes it so you CAN install the driver. We will do this with the Add-PrinterDriver command.

Add-PrinterDriver -Name "HP OfficeJet 5200 series PCL-3" -InfPath "C:\Windows\System32\DriverStore\FileRepository\hpygid24_v4.inf_amd64_f312bf16a5228084\hpygid24_v4.inf"

One thing I did find out in this was I believed I could put whatever I want in the name section. After many errors, I found out that this is not the case. If you open up the inf file, it will list names that will work. For the example above, I found the name in this section.


So make sure you have this correct before, and the driver should install without issue.

Create PrinterPort

Not a lot in this section. Run Add-PrinterPort, name it, and include the IP of the printer you are installing.

Add-PrinterPort -Name "Ports McGee" -PrinterHostAddress "IP Of Printer"

No gotchas, I can't even really add a throwaway line that I think is funny that the editors wish I would stop putting in blogs. They are not my supervisors, and I do what I want.

Install the printer

Finally, we can run Add-Printer. Point it to the driver you installed, the port you created, and name that thing. In my example, I named it Printy because that is what my daughter called our home printer. I considered coming up with my own name, but honestly, she terrifies me. I can't run the risk that she will see this blog later and punish me for disrespecting her naming scheme.

Add-Printer -DriverName "HP OfficeJet 5200 series PCL-3" -Name "Printy" -PortName "Ports McGee"

Putting it all together

So what have we learned? Use Group Policy if you can, but if you can't, a little prep work and some PowerShell can still get printers done without a mental breakdown. It will just be four lines.

pnputil.exe /a "\\fileshare\HPPrinter\*.inf" Add-PrinterDriver -Name "HP OfficeJet 5200 series PCL-3" -InfPath "C:\Windows\System32\DriverStore\FileRepository\hpygid24_v4.inf_amd64_f312bf16a5228084\hpygid24_v4.inf" Add-PrinterPort -Name "Ports McGee" -PrinterHostAddress "IP Of Printer" Add-Printer -DriverName "HP OfficeJet 5200 series PCL-3" -Name "Printy" -PortName "Ports McGee"

The next step is running this on all computers that need it. I would recommend PDQ Deploy and PDQ Inventory. You will be able to get each computer you need and installed on those machines in just minutes.

Jordan Hammond fun headshot
Jordan Hammond

Jordan had spent his life wondering why tasks he didn’t like to do had no options to complete themselves. Eventually he had to make that happen on his own. It turned out that he enjoyed making tasks complete themselves, and PDQ thought that is something he should talk about on the internet while drinking most Thursdays on the PDQ webcast.

Related articles