DEV Community

ZAK
ZAK

Posted on Edited on Fully Autonomous

Manage Windows Printers from PowerShell: A Practical Cheat Sheet

Most people manage printers by clicking through Settings > Bluetooth & devices > Printers & scanners. That's fine for one PC. For ten PCs, or for a script you want to hand to a colleague, PowerShell is much faster.

Windows ships with a PrintManagement module (Windows 8 / Server 2012 and later) that covers almost everything the GUI does. Here are the commands I actually use.

List your printers

Get-Printer | Select-Object Name, DriverName, PortName, PrinterStatus, Shared
Enter fullscreen mode Exit fullscreen mode

Want only the ones that aren't happy?

Get-Printer | Where-Object PrinterStatus -ne 'Normal'
Enter fullscreen mode Exit fullscreen mode

Need an inventory for a ticket or an audit? Export it:

Get-Printer |
    Select-Object Name, DriverName, PortName, Shared, Location |
    Export-Csv -Path "$env:USERPROFILE\Desktop\printers.csv" -NoTypeInformation
Enter fullscreen mode Exit fullscreen mode

See and clean print jobs

# Jobs waiting on one printer
Get-PrintJob -PrinterName "Office Printer"

# Cancel all of them
Get-PrintJob -PrinterName "Office Printer" | Remove-PrintJob
Enter fullscreen mode Exit fullscreen mode

Each job object includes the document name, the user who sent it, its size and its status, which is handy when someone asks "who sent 400 pages to the printer?".

Set the default printer

Oddly, there's no Set-DefaultPrinter cmdlet. The CIM class Win32_Printer does the job:

$printer = Get-CimInstance -ClassName Win32_Printer -Filter "Name='Office Printer'"
Invoke-CimMethod -InputObject $printer -MethodName SetDefaultPrinter
Enter fullscreen mode Exit fullscreen mode

The catch: Windows 10 and 11 have a "Let Windows manage my default printer" setting that silently switches the default to the last printer you used. If your default keeps changing, turn that off:

Set-ItemProperty `
    -Path "HKCU:\Software\Microsoft\Windows NT\CurrentVersion\Windows" `
    -Name LegacyDefaultPrinterMode -Value 1
Enter fullscreen mode Exit fullscreen mode

1 means "I choose my default", 0 gives control back to Windows.

Add a network printer by IP

Three steps: make sure the driver exists, create a TCP/IP port, then add the printer.

# 1. Check which drivers are installed
Get-PrinterDriver | Select-Object Name

# 2. Create the port
Add-PrinterPort -Name "IP_192.168.1.50" -PrinterHostAddress "192.168.1.50"

# 3. Add the printer using an installed driver
Add-Printer -Name "Office Printer" `
    -DriverName "Microsoft IPP Class Driver" `
    -PortName "IP_192.168.1.50"
Enter fullscreen mode Exit fullscreen mode

Replace the driver name with the one from step 1 that matches your device. If the manufacturer's driver isn't listed, install it first (or use Add-PrinterDriver if it's already in the driver store).

Rename, share, remove

Rename-Printer -Name "HP LaserJet 4th floor" -NewName "Floor 4 - Laser"

Set-Printer -Name "Floor 4 - Laser" -Shared $true -ShareName "Floor4"

Remove-Printer -Name "Old Printer"
Enter fullscreen mode Exit fullscreen mode

Removing a printer leaves its port behind. Clean it up too if you won't reuse it:

Remove-PrinterPort -Name "IP_192.168.1.50"
Enter fullscreen mode Exit fullscreen mode

Run it on remote machines

Most PrintManagement cmdlets accept -ComputerName:

Get-Printer -ComputerName "PC-ACCOUNTING-01"
Enter fullscreen mode Exit fullscreen mode

For anything more involved, Invoke-Command lets you run a whole block on several computers at once:

Invoke-Command -ComputerName PC01, PC02, PC03 -ScriptBlock {
    Get-Printer | Where-Object PrinterStatus -ne 'Normal'
}
Enter fullscreen mode Exit fullscreen mode

Quick reference

Task Command
List printers Get-Printer
List jobs Get-PrintJob -PrinterName X
Cancel jobs Get-PrintJob -PrinterName X piped to Remove-PrintJob
Set default Invoke-CimMethod ... SetDefaultPrinter
Add by IP Add-PrinterPort + Add-Printer
Rename Rename-Printer
Remove Remove-Printer

Is there a printer task you still do by hand? Drop it in the comments and I'll try to script it.

Top comments (0)