Powershell: Managing Printers and Drivers


1
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

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

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"

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 0×80070057,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

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

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"

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

  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 the driver as follows:

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: