Managing printers, printer drivers, and print jobs
You can use Windows PowerShell not only to view information
about printers, printer drivers, and print jobs on remote print
servers but also to manage printers, print drivers, and print jobs.
The following sections demonstrate two examples of this,
specifically:
In an earlier section of this lesson, you saw that one of the
print jobs for the HP LaserJet 5200 printer had Error for its
status. To determine which job it is, you can pipe the output from
the Get-PrintJob cmdlet into the Where-Object cmdlet to display all
jobs whose JobStatus property has “Error” in its value:
PS C:\> Get-PrintJob -ComputerName HOST7 -PrinterName "HP LaserJet 5200 PCL6" | `
where JobStatus -like "Error*"
Id ComputerName PrinterName DocumentName SubmittedTime JobStatus
-- ------------ ----------- ------------ ------------- ---------
3 HOST7 HP LaserJet ... Document 3 8/26/2012 2:08:06 PM Error, Print...
Having determined that job #3 is the problem, you could now
use the Remove-PrintJob cmdlet to cancel the problem job:
Remove-PrintJob -PrinterName "HP LaserJet 5200 PCL6" -ID 3
But instead of doing this, you can simply press the Up arrow
to display the previously executed command and pipe its output into
Remove-PrintJob as follows:
PS C:\> Get-PrintJob -ComputerName HOST7 -PrinterName "HP LaserJet 5200 PCL6" | `
where JobStatus -like "Error*" | Remove-PrintJob
Using the Get-PrintJob cmdlet again verifies that the problem
has been resolved:
PS C:\> Get-PrintJob -ComputerName HOST7 -PrinterName "HP LaserJet 5200 PCL6"
Id ComputerName PrinterName DocumentName SubmittedTime JobStatus
-- ------------ ----------- ------------ ------------- ---------
4 HOST7 HP LaserJet ... Document 2 8/26/2012 2:08:06 PM Printing
5 HOST7 HP LaserJet ... Document 1 8/26/2012 2:08:06 PM Normal
Installing a network printer
Installing a new network printer using Windows PowerShell
involves performing the following steps:
-
Installing a printer driver for the new printer
-
Creating a Standard TCP/IP Port for the printer
-
Installing the printer using the driver and port
specified
-
Performing any additional configuration needed for the
printer
For example, let’s say you want to install a printer that uses
the Dell Color Laser PCL6 Class Driver on your print server. You
could begin by using the Add-PrinterDriver cmdlet to install the
printer driver on the server:
PS C:\> Add-PrinterDriver -ComputerName HOST7 -Name "Dell Color Laser PCL6 Class Driver"
You could use the Get-PrinterDriver cmdlet to verify the
result as follows:
PS C:\> Get-PrinterDriver -ComputerName HOST7
Name PrinterEnvironment MajorVersion Manufacturer
---- ------------------ ------------ ------------
Dell Color Laser PCL6 Class Driver Windows x64 4 Dell
Samsung CLP-410 Series PCL6 Windows x64 4 Samsung
HP LaserJet 4200L PCL6 Class Driver Windows x64 4 HP
...
Next, you could use the Add-PrinterPort cmdlet to add a new
port for the printer like this:
PS C:\> Add-PrinterPort -ComputerName HOST7 -Name "172.16.11.63" `
-PrinterHostAddress "172.16.11.63"
You could use the Get-PrinterPort cmdlet to verify the
result:
PS C:\> Get-PrinterPort -ComputerName HOST7
Name ComputerName Description PortMonitor
---- ------------ ----------- -----------
172.16.11.55 HOST7 Standard TCP/IP Port TCPMON.DLL
172.16.11.63 HOST7 Standard TCP/IP Port TCPMON.DLL
COM1: HOST7 Local Port Local Monitor
...
Next, you could use the Add-Printer cmdlet to install, name,
and share the new printer using the driver and port previously
specified as follows:
PS C:\> Add-Printer -ComputerName HOST7 -Name "Sales Printer" `
-DriverName "Dell Color Laser PCL6 Class Driver" -Shared `
-ShareName "SalesPrint" -PortName "172.16.11.63"
The Get-Printer cmdlet could be used to verify the
installation of the new network printer:
PS C:\> Get-Printer -ComputerName HOST7 | ft Name,DriverName,PortName
Name DriverName PortName
---- ---------- --------
Sales Printer Dell Color Laser PCL6 ... 172.16.11.63
HP LaserJet 5200 PCL6 HP LaserJet 5200 PCL6 ... 172.16.11.55
...
Finally, you might want to change the default paper size for
the new printer from Letter to Legal like this:
PS C:\> Set-PrintConfiguration -ComputerName HOST7 -PrinterName "Sales Printer" `
-PaperSize Legal
You could then use the Get-PrintConfiguration cmdlet to verify
the result:
PS C:\> Get-PrintConfiguration -ComputerName HOST7 -PrinterName "Sales Printer" | `
fl PaperSize
PaperSize : Legal