Windows OS Hub
  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux
  • Home
  • About

Windows OS Hub

  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux

 Windows OS Hub / PowerShell / Managing Printers and Drivers on Windows with PowerShell

October 11, 2024

Managing Printers and Drivers on Windows with PowerShell

With PowerShell, you can automate common printer and printer driver management tasks in Windows. This guide explains how to create, delete, or share a printer from the PowerShell console; set a default printer; map a network printer; install or remove printer drivers; and manage local ports and print queues.

Contents:
  • Adding Printer Drivers to the DriverStore
  • How to Install Printer with PowerShell
  • List Printers on a Print Server Using PowerShell
  • Connect a Network Shared Printer with PowerShell
  • Set a Default Printer on Windows
  • How to Remove Printer with PowerShell

The built-in PrintManagement PowerShell module includes 22 cmdlets for managing printers, drivers, print ports, and queues:
Get-Command –Module PrintManagement
powershell module PrintManagement

  • Add-Printer – add (install) a new printer;
  • Add-PrinterDriver – install a new printer driver;
  • Add-PrinterPort – create a local print port;
  • Get-PrintConfiguration – display the printer configuration;
  • Get-Printer – list the printers installed on a computer;
  • Get-PrinterDriver – list the available printer drivers;
  • Get-PrinterPort – show the printer ports;
  • Get-PrinterProperty – show the printer properties;
  • Get-PrintJob – list the print tasks in the queue;
  • Read-PrinterNfcTag – get printer information from the NFC tag;
  • Remove-Printer – remove the printer;
  • Remove-PrinterDriver — remove the printer driver;
  • Remove-PrinterPort – remove the printer port;
  • Remove-PrintJob – delete a print job on the printer;
  • Rename-Printer – rename the printer;
  • Restart-PrintJob – restart the print job;
  • Resume-PrintJob – resume the paused print job;
  • Set-PrintConfiguration – set the printer configuration;
  • Set-Printer – update the printer configuration;
  • Set-PrinterProperty – change printer properties;
  • Suspend-PrintJob – suspend (pause) the print job;
  • Write-PrinterNfcTag – write information into the NFC tag.

Adding Printer Drivers to the DriverStore

The PrintManagement module has the Add-PrinterDriver cmdlet, which allows install a printer driver from an INF file. In fact, this cmdlet only allows adding drivers to an offline Windows image (just like the Add-WindowsDriver command, which lets you integrate drivers into offline Windows images).

To install a printer driver from an INF file, use the pnputil console command. Download the drivers for your printer model from the vendor’s website and extract them to a local folder. Then install the driver:

pnputil.exe -i -a "C:\drivers\KYOCERA\KyoClassicUniversalPCL6\OEMsetup.inf"

pnputil: install printer driver from inf file

Once the driver has been installed in the Windows Driver Store, it must be added to the list of available drivers for the print server:

Add-PrinterDriver -Name "Kyocera Classic Universaldriver PCL6"

Copy the exact name of the printer driver from the INF file.

find out printer driver name from inf file

List available print drivers:

Get-PrinterDriver

Get-PrinterDriver

How to Install Printer with PowerShell

Before creating a new printer, you must add a printer port. This can be a local port or it can be a network port (to send print jobs to a remote printer over the network). For example:
Add-PrinterPort -Name "LocalPort:" -ErrorAction -Verbose

Or specify the remote printer IP or print server name as the PrinterHostAddress.

Add-PrinterPort -Name "IP_192.168.10.26" -PrinterHostAddress "192.168.10.26"

To create a new printer in Windows, specify the printer name, driver, and port:

Add-Printer -Name "Ricoh IM 2702" -DriverName "Kyocera Classic Universaldriver PCL6" -PortName USB001 -Verbose

Add-Printer cmdlet: create new printer using powershell

Check that the new printer appears in the Control Panel and Settings app.

new printer in settings app
To rename the printer:

Rename-Printer -Name "Ricoh IM 2702" -NewName "Ricoh_2702"

To share a new printer over the network:

Set-Printer -Name "Ricoh IM 2702" -Shared $True -ShareName "Ricoh_2702"

Disable printer sharing:

Set-Printer -Name "Ricoh IM 2702" -Shared $False

List Printers on a Print Server Using PowerShell

List the printers installed on a computer:

Get-Printer

The command returns the printer names, types (local or network), driver, print port, whether the printer is shared, and whether it is published in Active Directory.

Get-Printer: list local printers with powershell

Most of the cmdlets in the PrintManagement module can be used to manage printers on remote computers (by using the -ComputerName parameter).

View a list of printers installed on a remote computer (print server):

Get-Printer -ComputerName rome-prnt1 | Format-List Name,DriverName

List shared printers on a computer:

Get-Printer -ComputerName rome-prnt1 | where Shared -eq $true | fl Name

Get printers that have duplex printing support:

Get-Printer | ForEach-Object { Get-PrintConfiguration -PrinterName $_.Name } | Where-Object { $_.DuplexingMode -ne "OneSided" }

powershell list printers with duplex twosided support

List all the color printers on a computer:

Get-Printer | ForEach-Object { Get-PrintConfiguration -PrinterName $_.Name } | where {$_.Color -eq $True}

Enable color printing mode for a printer:

Get-Printer 'HP Color LaserJet 150nw' | Set-PrintConfiguration -Color $true

Connect a Network Shared Printer with PowerShell

To connect a shared printer from a print server to a computer:

Add-Printer -ConnectionName \\rome-prnt1\HP3027

List the network printers connected to a computer:

Get-Printer | ?{$_.type -eq 'Connection'}

Remove a specific network printer connection:

Get-Printer -name \\rome-prnt1\HP3027| Remove-Printer -force

Remove all mapped network printers from your computer:

Get-Printer | ?{$_.type -eq 'Connection'} | Remove-Printer

Set a Default Printer on Windows

Windows automatically sets the default printer to the last printer that the user successfully printed to. To prevent Windows from reassigning the default printer, create the LegacyDefaultPrinterMode registry parameter:

Set-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows" -Name "LegacyDefaultPrinterMode" -Value 1 –Force

Then use the following commands to set the fixed default printer:

$Printer = Get-CimInstance -Class Win32_Printer -Filter "Name='Ricoh IM 2702'"
Invoke-CimMethod -InputObject $Printer -MethodName SetDefaultPrinter

set a default printer with powershell

How to Remove Printer with PowerShell

To remove a printer, use the command:

Remove-Printer -Name "HP LaserJet M1530"

You can then remove the printer driver from the print server:

Remove-PrinterDriver -Name "HP Universal Printing PCL 6"

In a domain environment, GPOs can be used to install printers.

Here are some other useful commands for sysadmin to manage typical printing tasks.

Send a test page for printing:

Invoke-CimMethod -MethodName printtestpage -InputObject (Get-CimInstance win32_printer | Where-Object Name -eq "HP LaserJet M1530")

Clear the printer queue:

Get-Printer -Name "HP LaserJet M1530" | Get-PrintJob | Remove-PrintJob

21 comments
3
Facebook Twitter Google + Pinterest
PowerShellWindows 10Windows 11Windows Server 2022
previous post
Invalid State of a Virtual Machine on VMWare ESXi
next post
How to Find Large Files on a Computer with PowerShell

Related Reading

How to Get My Public IP Address with...

October 24, 2023

Generating Strong Random Password with PowerShell

January 31, 2020

How to See Number of Active User Sessions...

March 16, 2024

Disks and Partitions Management with Windows PowerShell

March 11, 2024

Fix: DNS Resolution over VPN Doesn’t Work on...

December 27, 2023

How to Create and Use a RAM Drive...

December 18, 2023

FTP Server Quick Setup on Windows 10/11 and...

March 16, 2024

How to Backup Hyper-V Virtual Machines (Tutorial)

November 9, 2023

21 comments

Donald Shifflett May 22, 2014 - 4:56 pm

This post was very helpful since you explained that the driver has to be in the driver store to install the driver and how to put it there. I have been able to duplicate this process but we also install the 32 bit driver on our servers so I am trying to figure out the command for the install of that driver. I run the pnputil.exe command to add the 32 bit driver and I do not get any errors and when I run the Get-PrintDriver I see the PrinterEnviroment listed so I am using the command below to try to add the printer but it fails. Am I missing something?

Add-PrinterDriver -Name “HP Universal Printing PCL 6 (v5.8.0)” -ComputerName “Servername” -PrinterEnvironment “Windows NT x86”

Reply
MaxB May 23, 2014 - 5:54 am

You didn’t specify an error that this command returns
Command looks correct, try to run it locally on the server, not remotely
Also perhaps there is a mismatch in the bitness of driver

Reply
DJ May 27, 2014 - 10:03 pm

Using the same pattern at Donald above, I get a ‘driver not in driver store’ error when I try to add the HP Universal Printing (v5.7.0) x86 driver onto a win2012 server. I added all the drivers (x86 and x64) with:
pnputil.exe -i -a “\\path\to\x64\HPUniversalDriver\*.inf”
pnputil.exe -i -a “\\path\to\x86\HPUniversalDriver\*.inf”
then:
Add-PrinterDriver –Name “HP Universal Printing PS (v5.7.0)”
Add-PrinterDriver –Name “HP Universal Printing PS (v5.7.0)” -PrinterEnvironment “Windows NT x86”

The x64 driver is added but the x86 fails. I am doing this locally on the server.

This post helped me figure out the x64 drivers, thank you much for this post.

Reply
Scool January 14, 2015 - 7:14 pm

hello, i have same issue, i add driver to drivestore with pnputil, all is ok. and when i do a Add-PrinterDriver with PrinterEnvironment “Windows NT x86″ it say the driver is not in the Driverstore … 
no luck i spent hours to search how put x86 driver in my print server with command line (prefered powershell) .. but no luck ..found nothing .. only gui way ..
hope some have an answer.
best rehards
 

Reply
Francis Van Roie March 9, 2015 - 3:04 pm

I use this VBS to install Printer Drivers on our servers:
Function InstallPrinterDriver(strPrintServer,strDriverName,strPlatform,strDriverPath,strDriverINF)
    Set objWMIService = GetObject(“winmgmts:” _
    & “{impersonationLevel=impersonate}!\” & strPrintServer & “rootcimv2”)
    objWMIService.Security_.Privileges.AddAsString “SeLoadDriverPrivilege”, True

    Set objDriver = objWMIService.Get(“Win32_PrinterDriver”)

    objDriver.Name = strDriverName
    objDriver.SupportedPlatform = strPlatform
    objDriver.Version = 3
    objDriver.DriverPath = strDriverPath
    objDriver.Infname = strDriverPath & “” & strDriverINF
    intResult = objDriver.AddPrinterDriver(objDriver)

    if intResult<>0 then
        wscript.echo “ERROR: Driver not installed correctly !! ” & intResult & ” Run as admin?”
    else
        wscript.echo “SUCCESS: Driver is installed ” & intResult
    end if
    InstallPrinterDriver = intResult
End Function
            strDriverPath = “\serversharefolderdriverpath”
            strDriverINF  = “driver.inf”
            wscript.echo strDriverName & ” (x86) ==> ” & InstallPrinterDriver(strPrintServer,strDriverName,”Windows NT x86″,strDriverPath,strDriverINF)
            wscript.echo strDriverName & ” (x64) ==> ” & InstallPrinterDriver(strPrintServer,strDriverName,”Windows x64″,strDriverPath,strDriverINF)
 

Reply
Max March 11, 2015 - 8:05 am

Thank you for your helpful advice, but Powershell-way looks more simple 🙂

Reply
ronald May 14, 2015 - 6:57 pm

First thank you thank you and thank you
Perhaps you have figured out a problem i have spent all day on.  What if you dont know the name of the driver?   sure i know where the INF file is and i can open it in notpad ++ and find the name but what if it is cryptic or you are automating the process so clicking the INF you want to install will require a driver name.   
 
Add-PrinterDriver -ComputerName $server -Name ????  
 
I can pint to the INF file but that does no good.  Perhaps there is a way to do it.   I hope.    Powershell or batch.
 
Thanks
 
 

Reply
testing November 22, 2022 - 6:35 pm

I want to know this also. Is there a ways to add all printer drivers from the chosen *.inf file.
If not how does the Windows “have disk.. choose driver” dialog window work?

Reply
admin January 8, 2023 - 1:07 pm

You can install driver using pnputil
pnputil /i /a hpprintdriver.inf

Reply
Prabhu September 25, 2015 - 2:07 pm

They will not work against windows 2003 servers?
I get the below error 
add-printer : The specified print processor is invalid.
At line:1 char:1
+ add-printer -ComputerName servername -Name Testing4 -DriverName “Generic / Text On …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (MSFT_Printer:ROOT/StandardCimv2/MSFT_Printer) [Add-Printer], CimExceptio
    + FullyQualifiedErrorId : HRESULT 0x80070706,Add-Printer
 

Reply
Michael November 9, 2017 - 6:35 pm

This helped tremendously. Thanks for sharing.

Reply
Entreprise - Windows | Pearltrees March 15, 2019 - 8:30 am

[…] L’objectif de cet article sera d’installer un centralisateur de journaux d’événements Windows (logs) sur une machine virtuelle. Je vous invite dès à présent à rentrer dans un nouvel univers à l’image de « MATRIX » ! Dans cet article, j’ai décidé d’utiliser « VMWARE WORKSTATION 12 PRO » pour virtualiser le Trio « GRAYLOG2/Elasticsearch/MongoDB ». Objectifs de cet article. Managing Printers and Drivers with PowerShell in Windows 10 / Server 2016 | Windows OS Hub. […]

Reply
Szymon July 24, 2020 - 1:32 pm

Is there any way to create a port with the script for a output device that’s not reachable? You can do it manually, but the powershell script prompts an error.

Reply
admin July 28, 2020 - 3:27 am

You can create a TCP / IP print port even if the remote device is not reachable:
Add-printerport -Name “TCPPort:192.168.1.222” -PrinterHostAddress “192.168.1.222”

Reply
Szymon July 28, 2020 - 4:49 am

Thanks, we managed to make it work

Reply
Szymon July 24, 2020 - 1:33 pm

Add-PrinterPort : One or more specified parameters for this operation has an invalid value.
At C:\Users\sanchpab\Desktop\NewPSscript\Create_Config_PQ.ps1:273 char:5
+ Add-PrinterPort -Name $hostname -ComputerName $server -PrinterHos …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (MSFT_PrinterPortTasks:ROOT/StandardCimv2/MSFT_PrinterPortTasks) [Add-PrinterPor
t], CimException
+ FullyQualifiedErrorId : HRESULT 0x80070057,Add-PrinterPort

Reply
TV Dheeraj Kumar September 15, 2020 - 3:16 pm

Is there a way to add printer certificates using powershell

Reply
admin September 17, 2020 - 5:07 pm

What printer certificates are you talking about? Do you mean package-aware print drivers?

Reply
Andrei Kazanouski June 28, 2022 - 10:40 am

Set-Printer -Name “hp LaserJet 1015” -Shared $False -CimSession in4411864

Set-Printer: Cannot update an instance of the MSFT_3D Printer class using an instance view for the MSFT_Printer class. Specify the instance representation for the MSFT_3DPrinter class.

Why?

Reply
serg October 28, 2022 - 1:26 pm

Get a list of all printers

$printers = Get-Printer *

Get the list of all printers without One Sided printing mode

ForEach ($printer in $printers){Get-PrintConfiguration -ComputerName PRINTERSERVER -PrinterName $printer.Name | where {$_.DuplexingMode -ne “OneSided”}| ft -AutoSize}

Get a list of all printers with Color Mode on

ForEach ($printer in $printers){Get-PrintConfiguration -ComputerName PRINTERSERVER -PrinterName $printer.Name | where {$_.Color -eq $True}| ft -AutoSize}

Set Printer Color Mode to OFF

ForEach ($printer in $printers){
Set-PrintConfiguration -PrinterName $printer.Name -Color $False}

Set Printer Collate feature to ON

ForEach ($printer in $printers){ Set-PrintConfiguration -PrinterName $printer.Name -Collate $true}

Reply
Deploying Printers - Windows 10/11 December 8, 2022 - 1:07 pm

[…] you need to get a new copier on the network? In that situation I'd probably be using powershell: Managing Printers and Drivers with PowerShell in Windows 10 / Server 2016 | Windows OS Hub (ignore URL, it is for 10/11) I imagine there's probably a script somewhere that's ready-made to […]

Reply

Leave a Comment Cancel Reply

join us telegram channel https://t.me/woshub
Join WindowsHub Telegram channel to get the latest updates!

Recent Posts

  • Map a Network Drive over SSH (SSHFS) in Windows

    May 13, 2025
  • Configure NTP Time Source for Active Directory Domain

    May 6, 2025
  • Cannot Install Network Adapter Drivers on Windows Server

    April 29, 2025
  • Change BIOS from Legacy to UEFI without Reinstalling Windows

    April 21, 2025
  • How to Prefer IPv4 over IPv6 in Windows Networks

    April 9, 2025
  • Load Drivers from WinPE or Recovery CMD

    March 26, 2025
  • How to Block Common (Weak) Passwords in Active Directory

    March 25, 2025
  • Fix: The referenced assembly could not be found error (0x80073701) on Windows

    March 17, 2025
  • Exclude a Specific User or Computer from Group Policy

    March 12, 2025
  • AD Domain Join: Computer Account Re-use Blocked

    March 11, 2025

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Protecting Remote Desktop (RDP) Host from Brute Force Attacks
  • How to Set a User Thumbnail Photo in Active Directory
  • Implementing Dynamic Groups in Active Directory with PowerShell
  • Match Windows Disks to VMWare VMDK Files
  • FTP Server Quick Setup on Windows 10/11 and Windows Server
  • How to View and Close Open Files on Windows Server
  • How to Get My Public IP Address with PowerShell
Footer Logo

@2014 - 2024 - Windows OS Hub. All about operating systems for sysadmins


Back To Top