Windows OS Hub
  • Windows Server
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2012
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Group Policies
  • Windows Clients
    • Windows 10
    • Windows 8
    • Windows 7
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
  • PowerShell
  • Exchange
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2012
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Group Policies
  • Windows Clients
    • Windows 10
    • Windows 8
    • Windows 7
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
  • PowerShell
  • Exchange

 Windows OS Hub / Windows 8 / Powershell: Managing Printers and Their Drivers in Windows 8

April 29, 2014 Windows 8

Powershell: Managing Printers and Their Drivers in Windows 8

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

Get-Command –Module PrintManagement

cmdlets for manage printers with powershell in windows 8

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

Get-Help <cmdlet_name > -Detailed

Examples of the commands:

1
Get-Help <cmdlet_name > -Examples

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

Get-PrinterDriver

list installed print drivers with powershell

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"

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:

  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:\Install\HP\ …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidArgument: (MSFT_PrinterDriver:ROOT/StandardCimv2/MSFT_PrinterDriver) [Add-Printer
Driver], CimException
+ FullyQualifiedErrorId : HRESULT 0x80070057,Add-PrinterDriver

error then installing print driver with powershell

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

    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

    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"

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

install print driver in windows 8 with powershell

  Tip. There is some information about the «driver name» parameter. The name you specify should be equivalent to its internal system name, otherwise an error appears during the installation. You can find out the correct driver name using get-printerdriver command in the system where this driver has already been installed, or by manual check of the INF file of the driver.

Create an IP port to print using a network printer:

1
Add-PrinterPort -Name "IP_10.10.10.26" -PrinterHostAddress "10.10.10.26"

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

Add-Printer -Name hp3027_Office1 -DriverName "HP LaserJet M2027 MFP PCL6 Class Driver" -PortName IP_10.10.10.26 -Shared -ShareName "hp2027_1" –Published

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

install network printer with ip port

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

show-printers-windows8

The printer can be removed with the command:

1
Remove-Printer -Name "hp2027_Office1"

Remove-Printer -Name "hp2027_Office1"

Remove the driver as follows:

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

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

9 comments
0
Facebook Twitter Google + Pinterest
previous post
How to Set Up a Printer from the Command Line in Windows 8
next post
Password Security with Group Policy Preferences

Related Reading

How to Download APPX Installation File from Microsoft...

March 15, 2018

Enable Multiple Concurrent RDP Sessions in Windows 8.1...

February 21, 2018

How to Repair Broken EFI Bootloader in Windows...

February 14, 2018

How to Backup and Restore Boot Configuration (BCD)...

June 7, 2017

Windows 7/8.1 Update Error “The Processor is Not...

June 1, 2017

9 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 & “\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)
 

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
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

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange
  • Windows 10
  • Windows 8
  • Windows 7
  • Windows Server 2016
  • Windows Server 2012 R2
  • Windows Server 2008 R2
  • PowerShell
  • VMWare
  • MS Office

Recent Posts

  • Installing a Let’s Encrypt Free SSL Certificate on IIS in Windows Server 2012 R2

    April 19, 2018
  • How to Disable “Open File Security Warnings” in Windows 10, 8 and 7

    April 18, 2018
  • Outlook 2016: Manual Setup Exchange Account

    April 16, 2018
  • Cannot Access SMB Network Shares after Windows 10 1709 Upgrade

    April 12, 2018
  • Installing KMS Server on Windows Server 2012 R2

    April 11, 2018
  • How to Clear Pagefile.sys at Shutdown in Windows 10 / 8 / 7

    April 10, 2018
  • Searching AD Groups and Users using Wildcards

    April 5, 2018
  • How to access VMFS Datastore from Linux, Windows and ESXi

    April 3, 2018
  • SMB 1.0 Support in Windows Server 2012 R2 / Windows Server 2016

    April 2, 2018
  • Securing Administrative (Priveleged) Accounts in Active Directory

    March 27, 2018
woshub.com

Follow us

  • Facebook
  • Twitter
  • RSS
Popular Posts
  • How to hide Installed Programs from Programs and Features
  • How to Clean Up and Compress WinSxS Folder in Windows 8
  • Windows Doesn’t Assign Letters to External and USB Flash Drives
  • Auto-Mount VHD at Startup
  • How to Create a 4GB Windows 8.1 x64 Bootable USB Flash Drive
  • Access to more than 4GB of RAM on 32bit Windows 8 (x86)
  • How to Export Drivers Using Powershell in Windows 8.1 U1
Footer Logo

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


Back To Top