How to install printers with PowerShell

Brock Bingham candid headshot
Brock Bingham|Updated June 21, 2023
Illustration of block with Powershell logo
Illustration of block with Powershell logo

Printers are the worst. It’s the one thing that people can agree on these days. When a printer acts up, it’s difficult to suppress the desire to grab a baseball bat and head to the nearest open field with the printer in tow. However, my therapist assures me that violence is never the answer. Instead, let’s focus that r̶a̶g̶e̶ energy into learning how to manage printers using PowerShell, which might make them slightly less terrible.

Installing a printer from a print server with PowerShell

If you have a print server, installing printers using PowerShell is almost effortless. It’s what we in the PowerShell business call a one-liner. Here’s how it works.

  1. Enter PowerShell into the Windows search field.

  2. Launch your favorite flavor of PowerShell. For this example, I’m using PowerShell 7, but Windows PowerShell (PS ver. 5.1) should work fine.

    Search for and launch PowerShell.

  3. Enter and execute this command, replacing <printserver> and <printername> with your environment information:

    Add-Printer -ConnectionName \\<printserver>\<printername>

Nice and easy. The print server adds the driver to the store, installs the driver, creates the printer port, and installs the printer while I take all the credit. It’s a win-win situation, which is why I continue to vehemently endorse PowerShell.

How to install printers using PowerShell

Things get a bit more complicated if you don’t have access to a print server.

Here are the necessary steps to install a printer using PowerShell.

  1. Add the print driver to the driver store.

  2. Install the print driver.

  3. Create the printer port.

  4. Install the printer.

This may sound a bit daunting, but I assure you that each of these steps can be accomplished with relatively simple commands.

1. Adding drivers to the driver store with PowerShell

While it would be amazing for your computer to already have the driver file you need, it’s also unrealistic. Thankfully adding drivers to the driver store is a simple process.

This step assumes you already have the necessary INF driver file for your printer. If you don’t already have the driver file, you should be able to download it from the printer manufacturer’s website. Once you have the file, copy its directory path because we’ll need it for the command. This can be a UNC or local path.

Here’s the command.

Pnputil /add-driver <”inf_path”>

Ensure you replace <”inf_path”> with the path to your INF file. Here’s the outcome of the command I ran while my INF file was located in my Documents folder.

INF import results using PowerShell.

Before you grab your pitchfork, yes, I know pnputil isn’t really a PowerShell command. But it works, and you can run it from a PowerShell console, so I’m going to count it.

2. Installing printer drivers with PowerShell

Now that we’ve added our driver package to the driver store, we’re ready to install it. First, we need to find the exact name of the driver, which is located in the INF file. Open the INF file, locate the driver name, and save the name because we’ll need it for the command. Here is what the name looks like for my HP driver.

Copy the printer name out of the INF file.

With our driver name handy, we’re ready for the command.

Add-PrinterDriver -Name <”driver_name”> -InfPath <”driver_path”>

Obviously, you’ll want to add your driver name and driver path to your script. Here’s the full command I used for my driver.

Add-PrinterDriver -Name “HP OfficeJet Pro 6970 PCL-3” -InfPath "C:\Windows\System32\DriverStore\FileRepository\hpygid20_v4.inf_amd64_6dcca7f9f7ba29dc\hpygid20_v4.inf"

3. Creating printer ports with PowerShell

Creating printer ports with PowerShell is straightforward. The most difficult part is coming up with a catchy name, so give yourself plenty of time with this step. Once you’ve figured out your port name, you’re ready for the command.

Add-PrinterPort -Name <”port_name”> -PrinterHostAddress <printer_IP_address>
Adding a printer port using PowerShell.

Congrats! You’ve created a printer port with PowerShell. While most people would recommend giving the port a descriptive name, I think my creative name better reflects my eating habits, which is important.

4. Installing printers with PowerShell

We’ve made it to the final step of the process: installing the actual printer. This is where we bring all the previous steps together in a mighty crescendo of PowerShell and behold our glorious results. We also get to think up another creative name, this time for the printer. Here’s the command.

Add-Printer -DriverName <”driver_name”> -Name <”printer_name”> -PortName <”port_name”>

And just like that, Sir Jams Alot has been added to my environment and is ready to jam whenever I’m running late for a meeting.

Installing a printer using PowerShell.
Confirming the printer has been installed.

The full PowerShell script for installing printers

Here’s the full script to add printers to your computer with PowerShell.

Pnputil /add-driver <”inf_path”> Add-PrinterDriver -Name <”driver_name”> -InfPath <”driver_path”> Add-PrinterPort -Name <”driver_name”> -PrinterHostAddress <printer_ip_address> Add-Printer -DriverName <”driver_name”> -Name <”printer_name”> -PortName <”port_name”>

Ensure you replace everything designated with left- and right-angle brackets with the proper information, and you should be good to go.

If you intend to deploy this script to other computers on your network, I recommend saving the print driver on a file share that all your endpoints can access. I also recommend using a tool designed to deploy scripts, like PDQ Deploy or PDQ Connect. PDQ Deploy specializes in distributing packages and scripts to your on-prem devices. PDQ Connect is an agent-based solution for managing and distributing packages and scripts to remote endpoints. You can try both solutions free for 14 days.

Managing printers at scale recommendations

If your goal is to manage printers at scale, such as for an organization, I would be remiss not to mention Group Policy and Intune. If these solutions are available, use them over PowerShell.

Don’t get me wrong: I’m a hardcore PowerShell fanatic. I’ve written dozens of PowerShell articles, and I even guest starred on The PowerShell Podcast. But — sometimes there are better tools for the job, even though that hurts to say. In this case, that’s Group Policy and Intune. With way more management control, including security and networking options, Group Policy and Intune give you the tools necessary to manage printers at scale. However, if this is just for a few devices, PowerShell is more than capable of getting that pesky printer installed.

Brock Bingham candid headshot
Brock Bingham

Born in the '80s and raised by his NES, Brock quickly fell in love with everything tech. With over 15 years of IT experience, Brock now enjoys the life of luxury as a renowned tech blogger and receiver of many Dundie Awards. In his free time, Brock enjoys adventuring with his wife, kids, and dogs, while dreaming of retirement.

Related articles