PowerShell add printer guide

How to add a printer with PowerShell

To add a printer with PowerShell, put its driver in the Windows driver store, register the driver, create a TCP/IP port for the printer's IP address, then add the printer on that port. Four commands, run as an administrator or as SYSTEM from an RMM, add the printer for every user of the PC.

Last updated

How do I add a printer by IP address in PowerShell?

Run these four commands in an elevated PowerShell window, with your driver's path, its name and your printer's address.

# 1. Put the driver package in the driver store, from the folder holding its .inf
pnputil.exe /add-driver "C:\Drivers\Vendor\driver.inf" /install

# 2. Register the driver, by its name exactly as the .inf lists it
Add-PrinterDriver -Name "Vendor Universal PCL6"

# 3. Create a TCP/IP port for the printer's address (raw printing, port 9100)
Add-PrinterPort -Name "IP_192.168.1.50" -PrinterHostAddress "192.168.1.50"

# 4. Add the printer on that port, with that driver
Add-Printer -Name "Front Desk" -DriverName "Vendor Universal PCL6" -PortName "IP_192.168.1.50"

The names and addresses are examples. Use your driver's .inf path and its exact model name.

How do I add a printer driver with PowerShell?

In two steps: pnputil /add-driver puts the package in the driver store, then Add-PrinterDriver registers it with the print spooler.

Add-PrinterDriver only registers drivers that are already in the driver store, which is why it reports that a driver does not exist when the package has not been added first. The name it needs is the model name in the .inf file, with the same capitals and spaces. On 64-bit Windows the package must be signed, or Windows refuses it.

How do I make the script safe to run again?

Check before adding, so a second run changes nothing.

$port = "IP_192.168.1.50"
if (-not (Get-PrinterPort -Name $port -ErrorAction SilentlyContinue)) {
    Add-PrinterPort -Name $port -PrinterHostAddress "192.168.1.50"
}
if (-not (Get-Printer -Name "Front Desk" -ErrorAction SilentlyContinue)) {
    Add-Printer -Name "Front Desk" -DriverName "Vendor Universal PCL6" -PortName $port
}

How do I set duplex and color defaults?

With Set-PrintConfiguration after the printer is added:

Set-PrintConfiguration -PrinterName "Front Desk" -DuplexingMode TwoSidedLongEdge -Color $false

How do I run it from an RMM?

  1. Copy the driver folder to each machine first, or to a share the machine can read as SYSTEM.
  2. Run the script as SYSTEM, in 64-bit PowerShell. If your RMM's agent is a 32-bit process, call %WINDIR%\SysNative\WindowsPowerShell\v1.0\powershell.exe, or Windows hands the script to 32-bit PowerShell.
  3. Target it at the machines that should have the printer, and keep that targeting up to date as machines move between offices.
  4. Check each machine's output for failures, since nothing reports them for you.

What is the alternative to a script per printer?

One script per machine that installs an agent, and printers managed by site from then on.

With Xenoprint, your RMM runs one installer per client, once per machine. After that you add, change and remove printers in a portal, by site; each machine installs its site's printers and drivers itself, as SYSTEM, and reports what worked and what failed. Only drivers certified by Microsoft (WHQL) or included with Windows are installed. See RMM integrations for the steps in NinjaOne, Datto RMM, ConnectWise Automate, Kaseya and N-central.

PowerShell from your RMMXenoprint
A new printerA new or changed script, and new targetingAdd it to the site in the portal
DriversCopied to each machine by youDownloaded by each machine from your driver library
A machine moves officeChange its targeting by handSite rules move it, and it gets the new office's printers
Did it work?Read each job's outputPer machine, in the portal
A user deletes itGone until the script runs againPut back automatically, within set limits

Questions

Why does Add-PrinterDriver say the driver does not exist?

Because it registers only drivers already in the Windows driver store. Add the package first with pnputil /add-driver and the path to its .inf file, then use the driver's name exactly as the .inf lists it, including capitals and spaces.

Do I need administrator rights to add a printer with PowerShell?

Yes, for anything that changes the PC: adding a driver, a port or a local printer. RMM tools run scripts as SYSTEM, which has those rights. Connecting to a shared printer with Add-Printer -ConnectionName is the one case a standard user can run, and it follows Point and Print rules.

How do I remove a printer with PowerShell?

Run Remove-Printer -Name with the printer's name. Its port and driver stay on the PC; remove them with Remove-PrinterPort and Remove-PrinterDriver once no other printer uses them, or leave them, since they do nothing on their own.

Try it on one site

Free for 30 days during the beta, with unlimited agents. No card needed.