Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu

 Windows OS Hub / PowerShell / Managing Printers and Drivers with PowerShell in Windows 10 / Server 2016

February 20, 2023 PowerShellWindows 10Windows Server 2012 R2Windows Server 2016

Managing Printers and Drivers with PowerShell in Windows 10 / Server 2016

In the previous article, we looked at the old-school VBS scripts that can be used to manage printers and print operations in all Windows versions, starting from Windows XP. Today we are going to consider typical commands to install, manage and remove printers, print ports, drivers, and queues using PowerShell. These ways of managing printers from PowerShell CLI can be used in modern operating systems – Windows 10 / 8.1 and Windows Server 2019 / 2016 / 2012 R2.

Contents:
  • PowerShell module: PrintManagement
  • Adding Printer Drivers to the DriverStore
  • How to Install Printer Using PowerShell?
  • List Installed Printers on a Print Server
  • Connecting to a Network Shared Printer with PowerShell
  • How to Remove a Printer Using PowerShell?

PowerShell module: PrintManagement

Along with the release of Windows 8.1 and Windows Server 2012 R2, Microsoft released a new version of PowerShell 4.0 (a part of Windows Management Framework 4.0), which significantly extended the list of the Windows-based print server management cmdlets. You can get the full list of print, driver and print queue management cmdlets available in the PrintManagement module on Windows 10 (PowerShell v5) with the following command:

Get-Command –Module PrintManagement

powershell module PrintManagementThe PrintManagement module include 22 PowerShell cmdlets for managing printers, drivers, print ports, and queues:

  • Add-Printer – add (install) new printer;
  • Add-PrinterDriver – install new print driver;
  • Add-PrinterPort – create local print port;
  • Get-PrintConfiguration – display printer configuration;
  • Get-Printer – display the list of printers installed on the computer;
  • Get-PrinterDriver – display the list of the installed drivers;
  • Get-PrinterPort – displays the list of the printer ports;
  • Get-PrinterProperty – show printer properties;
  • Get-PrintJob – get a list of printer print jobs;
  • 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.

To get detailed information about the syntax of any command, use the following command:

Get-Help <cmdlet_name> -Detailed

Examples of using commands:

Get-Help < cmdlet_name> -Examples

Let’s look at a few examples of typical printer management tasks using PowerShell in Windows 10.

Adding Printer Drivers to the DriverStore

To list the print drivers that are installed in the Windows DriverStore:

Get-PrinterDriver

list installed print drivers with powershell

Then, install a new printer driver in the system. For example, you want to install the popular print driver “HP Universal Printing PCL 6”. According to the documentation, the PowerShell command to add a print driver should be as follows:

Add-PrinterDriver -Name "HP Universal Printing PCL 6" -InfPath "C:\Distr\HP-pcl6-x64\hpcu118u.inf"

However, when trying to install a driver in this way, the following error message appears:


Add-PrinterDriver : One or more specified parameters for this operation has an invalid value.At line:1 char:1+ Add-PrinterDriver -Name “HP Universal Printing PCL 6” -InfPath “C:\Di …+ ~~~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo          : InvalidArgument: (MSFT_PrinterDriver:ROOT/StandardCimv2/MSFT_PrinterDriver) [Add-PrinterDriver], CimException   + FullyQualifiedErrorId : HRESULT 0x80070057,Add-PrinterDriver

error then installing print driver using powershell cmdlet Add-PrinterDriver

It turns out that the driver from the INF file can only be installed if it already exists in the DriverStore. It appears that you can’t install a print driver that is not in the Driver Store using Add-PrinterDriver command. To add a driver to the DriverStore, you can use:

  • the VBS script described in the previous article;
  • the utility — pnputil.exe. The command can looks as follow: pnputil.exe -i -a C:\Distr\HP-pcl6-x64\hpcu118u.inf (installs the specific printer driver) or pnputil.exe -i -a C:\Distr\HP-pcl6-x64\*.inf (installs all the drivers found in the INF files in the specified directory);pnputil - install print driver to driverstore
  • the cmdlet Add-WindowsDriver that allows to integrate drivers into the offline Windows image.

After adding a printer driver to the driver repository, you should install it on the print server:

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

Add-PrinterDriver PowerShell

Tip. How to find out what should you specify in the field of the print driver name when installing the driver via PowerShell? The specified print driver name must exactly match its internal system name, otherwise an error will appear during the driver installation. You can find out the correct driver name using the get-printerdriver command on a computer where this print driver is already installed, or by manually examining the driver’s .inf file.print driver name in the inf file

How to Install Printer Using PowerShell?

Create an IP port for a network printer (here you can specify both the IP address of the network printer and the name of the remote print server):

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

Before adding a new IP print port, you can check if it exists:

$portName = "IP_192.168.10.26"
$checkPortExists = Get-Printerport -Name $portname -ErrorAction SilentlyContinue
if (-not $checkPortExists) {
Add-PrinterPort -name $portName -PrinterHostAddress "192.168.10.26"
}

With the help of the following command, we will install and share a new printer on the computer:

Add-Printer -Name hp3027_Office1_Buh -DriverName "HP LaserJet M3027 MFP PCL6 Class Driver" -PortName IP_192.168.10.26 -Shared -ShareName "hp3027_1_BUh" –Published

install network printer with ip port

Note: Note that to perform the same operation (install and share a printer) using VBS scripts (Printing Admin scripts), you should perform two different commands.

After running these commands, a new shared printer with the name “hp3027_Office1” will appear in the system.

show-printers-windows8

To rename the printer, just run the command:

Rename-Printer -Name "hp3027_1_Buh" -NewName "hp3027_F1_Salary"

List Installed Printers on a Print Server

Let’s display the full list of printers installed on this computer:

Get-Printer

As you can see, the command shows the printer name, type (local or network), driver, print port, whether the printer is shared and published in the Active Directory.

Get-Printer: list local printers with powershell

Most PrintManagement cmdlets can be used to view status and manage printers, drivers and print queues on remote computers (print servers). The name of the remote computer or server is specified as an argument of the –ComputerName parameter.

You can get information about installed printers on a remote computer using PowerShell command:

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

To display only a list of shared printers, use the command:

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

Connecting to a Network Shared Printer with PowerShell

To connect the shared printer from the print server, use the command:

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

Windows 10 uses the latest printer that was used for printing as the default printer. If you want to use a fixed default printer, run the command:

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

To set the default printer, you can use the following commands:

$wsnObj = New-Object -COM WScript.Network
$wsnObj.SetDefaultPrinter(%PrinterName%)

How to Remove a Printer Using PowerShell?

To remove a printer, you need to run the following PowerShell command:

Remove-Printer -Name "hp3027_L1_O1"

You can remove a specific driver using the Remove-PrinterDriver cmdlet:

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

21 comments
2
Facebook Twitter Google + Pinterest
previous post
Invalid State of a Virtual Machine on VMWare ESXi
next post
How to Find Large Files on Your Computer Using PowerShell

Related Reading

Zabbix: How to Get Data from PowerShell Scripts

October 27, 2023

Tracking Printer Usage with Windows Event Viewer Logs

October 19, 2023

PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

October 15, 2023

How to Query and Change Teams User Presence...

October 8, 2023

How to Use Ansible to Manage Windows Machines

September 25, 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

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMWare
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • Zabbix: How to Get Data from PowerShell Scripts

    October 27, 2023
  • Tracking Printer Usage with Windows Event Viewer Logs

    October 19, 2023
  • PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

    October 15, 2023
  • Reset Root Password in VMware ESXi

    October 12, 2023
  • How to Query and Change Teams User Presence Status with PowerShell

    October 8, 2023
  • How to Increase Size of Disk Partition in Ubuntu

    October 5, 2023
  • How to Use Ansible to Manage Windows Machines

    September 25, 2023
  • Installing Language Pack in Windows 10/11 with PowerShell

    September 15, 2023
  • Configure Email Forwarding for Mailbox on Exchange Server/Microsoft 365

    September 14, 2023
  • How to View and Change BIOS (UEFI) Settings with PowerShell

    September 13, 2023

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Deploy PowerShell Active Directory Module without Installing RSAT
  • Managing User Photos in Active Directory Using ThumbnailPhoto Attribute
  • RDP Brute Force Protection with PowerShell and Windows Firewall Rules
  • Match Windows Disks to VMWare VMDK Files
  • Active Directory Dynamic User Groups with PowerShell
  • Auditing Weak Passwords in Active Directory
  • Assign Multiple IP Addresses (Aliases) to a Single NIC
Footer Logo

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


Back To Top