In the previous article we have studied old school VBS scripts that can be used to manage printers and printing system in all Windows versions, starting from Windows XP. Today, we are going to consider typical commands and procedures of printer and printer driver management in Windows 8.1 / Server 2012 R2 using Powershell.
Microsoft released a new PowerShell version 4.0 simultaneously with the launch of Windows 8.1 and Windows Server 2012 R2. The new version is a part of Windows Management Framework 4.0, and has a significantly extended the list of Windows-based print server management cmdlets. You can get the full list of print, driver and print queue management cmdlets available in Posh v4 with the following command:
1 | Get-Command –Module PrintManagement |
22 cmdlets are available in Powershell:
- Add-Printer – installs a printer
- Add-PrinterDriver – installs a printer driver
- Add-PrinterPort – creates a printer port
- Get-PrintConfiguration – displays printer configuration
- Get-Printer – displays the list of the installed printers
- Get-PrinterDriver – displays the list of the installed drivers
- Get-PrinterPort – displays the list of the installed printer ports
- Get-PrinterProperty – shows printer properties
- Get-PrintJob – shows the list of print jobs of the printer
- Read-PrinterNfcTag – reads information about a printer from the NFC tag
- Remove-Printer – removes a printer
- Remove-PrinterDriver — removes a driver
- Remove-PrinterPort – removes a printer port
- Remove-PrintJob – removes a print job
- Rename-Printer – renames a printer
- Restart-PrintJob – restarts a print job
- Resume-PrintJob – resumes a paused print job
- Set-PrintConfiguration – sets printer configuration
- Set-Printer – updates the printer configuration
- Set-PrinterProperty – changes printer properties
- Suspend-PrintJob – suspends a print job
- Write-PrinterNfcTag – writes information into the NFC tag
To get detailed information about the syntax of any command, use the following command:
1 | Get-Help <cmdlet_name > -Detailed |
Examples of the commands:
1 | Get-Help <cmdlet_name > -Examples |
Let’s look at the typical examples of cmdlets used in printer management in Windows 8.
Let’s display the list of printer drivers in the system:
1 | Get-PrinterDriver |
Then, install a new printer driver in the system, for example HP Universal Printing PCL 6. According to the documentation, the command to add a driver should be as follows:
1 | Add-PrinterDriver -Name "HP Universal Printing PCL 6" -InfPath "C:\Install\HP\hpcu160u.inf" |
However, when trying to install a driver this way, the following error message appears:
At line:1 char:1
+ Add-PrinterDriver -Name “HP Universal Printing PCL 6” -InfPath “C:\Install\HP\ …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (MSFT_PrinterDriver:ROOT/StandardCimv2/MSFT_PrinterDriver) [Add-Printer
Driver], CimException
+ FullyQualifiedErrorId : HRESULT 0x80070057,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 driver that doesn’t exist in the DriverStore using Add-PrinterDriver command. To add a driver to the DriverStore, you can use:
- a VBS script described in the previous article
- the utility — pnputil.exe. The format is as follows:
1
Pnputil –a pnputil.exe -i -a C:\Install\HP\hpcu160u.inf
(installs the specific printer driver) or
1
pnputil.exe -i -a C:\Install\HP\*.inf
(installs all the drivers found in the INF files in the specified directory)
- the cmdlet Add-WindowsDriver that allows to integrate drivers in the offline Windows image
After adding a printer driver to the DriverStore, you should install it on the printer server.
1 | Add-PrinterDriver -Name "HP Universal Printing PCL 6" |
Create an IP port to print using a network printer:
1 | Add-PrinterPort -Name "IP_10.10.10.26" -PrinterHostAddress "10.10.10.26" |
We create a new printer in the system and publish (i.e. share) it using the following command:
1 | Add-Printer -Name hp3027_Office1 -DriverName "HP LaserJet M2027 MFP PCL6 Class Driver" -PortName IP_10.10.10.26 -Shared -ShareName "hp2027_1" –Published |
After running these commands, a new shared printer with the name «hp3027_Office1»will appear in the system.
The printer can be removed with the command:
1 | Remove-Printer -Name "hp2027_Office1" |
Remove the driver as follows:
1 | Remove-PrinterDriver -Name "HP Universal Printing PCL 6" |
9 comments
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”
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
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.
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
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 & “\root\cimv2”)
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 = “\\server\share\folder\driverpath”
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)
Thank you for your helpful advice, but Powershell-way looks more simple 🙂
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
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
This helped tremendously. Thanks for sharing.