Windows Server 2012 includes a new Windows PowerShell module
called PrintManagement that contains cmdlets you can use for viewing
and managing printers, printer drivers, and print jobs. You can use
the Get-Command cmdlet to display a list of PrintManagement cmdlets as
follows:
PS C:\> Get-Command -Module PrintManagement
CommandType Name ModuleName
----------- ---- ----------
Function Add-Printer PrintManagement
Function Add-PrinterDriver PrintManagement
Function Add-PrinterPort PrintManagement
Function Get-PrintConfiguration PrintManagement
Function Get-Printer PrintManagement
Function Get-PrinterDriver PrintManagement
Function Get-PrinterPort PrintManagement
Function Get-PrinterProperty PrintManagement
Function Get-PrintJob PrintManagement
Function Remove-Printer PrintManagement
Function Remove-PrinterDriver PrintManagement
Function Remove-PrinterPort PrintManagement
Function Remove-PrintJob PrintManagement
Function Rename-Printer PrintManagement
Function Restart-PrintJob PrintManagement
Function Resume-PrintJob PrintManagement
Function Set-PrintConfiguration PrintManagement
Function Set-Printer PrintManagement
Function Set-PrinterProperty PrintManagement
Function Suspend-PrintJob PrintManagement
The following sections describe how to perform the following
tasks:
-
Retrievea list of printers installed on a print
server
-
View information about pending print jobs
-
View information about printers
-
View information about printer drivers and ports
Retrieve a list of printers installed on a print
server
You can use the Get-Printer cmdlet to display a list of the
installed printers on a print server. For example, the following
command shows that there are four printers installed on a remote
print server named HOST7:
PS C:\> Get-Printer -ComputerName HOST7 | Format-List Name,DriverName
Name : Samsung CLP-410 Series PCL6
DriverName : Samsung CLP-410 Series PCL6
Name : HP LaserJet 4200L PCL6
DriverName : HP LaserJet 4200L PCL6 Class Driver
Name : Microsoft XPS Document Writer
DriverName : Microsoft XPS Document Writer v4
Name : HP LaserJet 5200 PCL6
DriverName : HP LaserJet 5200 PCL6 Class Driver
You can pipe the output from the preceding command into the
Where-Object cmdlet to determine which of these printers are
shared:
PS C:\> Get-Printer -ComputerName HOST7 | where Shared -eq $true | fl Name
Name : Samsung CLP-410 Series PCL6
Name : HP LaserJet 4200L PCL6
Name : HP LaserJet 5200 PCL6
Using the Get-Printer cmdlet as follows indicates that one of
the printers on HOST7 has Error for its status:
PS C:\> Get-Printer -ComputerName HOST7 | where PrinterStatus -eq Error | `
fl Name,JobCount
Name : HP LaserJet 5200 PCL6
JobCount : 3
To view more information about the cause of this error, you
can use the Get-PrintJob cmdlet like this:
PS C:\> Get-PrintJob -ComputerName HOST7 -PrinterName "HP LaserJet 5200 PCL6"
Id ComputerName PrinterName DocumentName SubmittedTime JobStatus
-- ------------ ----------- ------------ ------------- ---------
3 HOST7 HP LaserJet ... Document 3 8/26/2012 2:08:06 PM Error, Print...
4 HOST7 HP LaserJet ... Document 2 8/26/2012 2:08:06 PM Normal
5 HOST7 HP LaserJet ... Document 1 8/26/2012 2:08:06 PM Normal
The first print job in the queue (job #3) is generating the
error condition. You can find out more information about this job as
follows:
PS C:\> Get-PrintJob -ComputerName HOST7 -PrinterName "HP LaserJet 5200 PCL6" | `
where Id -eq 3 | fl JobStatus,UserName
JobStatus : Error, Printing, Retained
UserName : kberg
The fact that the job status includes
Retained suggests that either the print job is
corrupted or the print device is offline or out of paper. Either
way, user Karen Berg should probably be informed because the print
job belongs to her.
You can also use the Windows PowerShell pipeline with certain
combinations of cmdlets in the PrintManagement module. For example,
you can pipe the output from the Get-Printer cmdlet into the
Get-PrintJob cmdlet to view all pending print jobs on all printers
installed on a print server:
PS C:\> Get-Printer -ComputerName HOST7 | Get-PrintJob
Id ComputerName PrinterName DocumentName SubmittedTime JobStatus
-- ------------ ----------- ------------ ------------- ---------
2 HOST7 Samsung CLP-... Document 4 8/27/2012 3:54:33 PM Normal
3 HOST7 HP LaserJet ... Document 3 8/26/2012 2:08:06 PM Error, Print...
4 HOST7 HP LaserJet ... Document 2 8/26/2012 2:08:06 PM Normal
5 HOST7 HP LaserJet ... Document 1 8/26/2012 2:08:06 PM Normal
You can use the Get-PrinterConfiguration cmdlet to display the
configuration settings for a particular printer:
PS C:\> Get-PrintConfiguration -ComputerName HOST7 -PrinterName "HP LaserJet 5200 PCL6"
PrinterName ComputerName Collate Color DuplexingMode
----------- ------------ ------- ----- -------------
HP LaserJet ... HOST7 True False OneSided
Using the pipeline also allows you to display configuration
settings for all printers installed on a remote printer
server:
PS C:\> Get-Printer -ComputerName HOST7 | Get-PrintConfiguration
PrinterName ComputerName Collate Color DuplexingMode
----------- ------------ ------- ----- -------------
Samsung CLP-... HOST7 False True OneSided
Microsoft XP... HOST7 False True OneSided
HP LaserJet ... HOST7 True False OneSided
HP LaserJet ... HOST7 True False OneSided
If you want to list all color printers installed on HOST7, you
can do it like this:
PS C:\> Get-Printer -ComputerName HOST7 | Get-PrintConfiguration | `
where Color -eq $true | fl PrinterName
PrinterName : Microsoft XPS Document Writer
PrinterName : Samsung CLP-410 Series PCL6
Another cmdlet Get-PrinterProperty allows you to display
additional properties for an installed printer like this:
PS C:\> Get-PrinterProperty -ComputerName HOST7 `
-PrinterName "Samsung CLP-410 Series PCL6"
ComputerName PrinterName PropertyName Type Value
------------ ----------- ------------ ---- -----
HOST7 Samsung CLP-410 S... FormTrayTable String
HOST7 Samsung CLP-410 S... Config:DuplexUnit String FALSE
HOST7 Samsung CLP-410 S... Config:OptTray2 String FALSE
HOST7 Samsung CLP-410 S... Config:OptTray3 String FALSE
HOST7 Samsung CLP-410 S... Config:OptTray4 String FALSE
HOST7 Samsung CLP-410 S... Config:OptTray5 String FALSE
Earlier in this lesson, you used the Get-Printer cmdlet
earlier to list the printers installed on print server HOST7:
PS C:\> Get-Printer -ComputerName HOST7 | Format-List Name,DriverName
Name : Samsung CLP-410 Series PCL6
DriverName : Samsung CLP-410 Series PCL6
Name : HP LaserJet 4200L PCL6
DriverName : HP LaserJet 4200L PCL6 Class Driver
Name : Microsoft XPS Document Writer
DriverName : Microsoft XPS Document Writer v4
Name : HP LaserJet 5200 PCL6
DriverName : HP LaserJet 5200 PCL6 Class Driver
The drivers for the two HP printers have “Class Driver” in
their names, which indicates they are v4 drivers, and the driver for
the Microsoft XPS Document Writer printer is clearly a v4 driver as
well. But what about the Samsung driver? The driver for this printer
has neither “v4” nor “Class Driver” in its driver name, so could it
be a v3 driver instead of a v4 type?
An easy way to determine this is to use the Get-PrinterDriver
cmdlet like this:
PS C:\> Get-PrinterDriver -ComputerName HOST7 -Name "Samsung*"
Name PrinterEnvironment MajorVersion Manufacturer
---- ------------------ ------------ ------------
Samsung CLP-410 Series PCL6 Windows x64 4 Samsung
Clearly, the Samsung driver is of the v4 type.
Another useful cmdlet is Get-PrinterPort, which allows you to
retrieve a list of printer ports installed on a print server. For
example, the following command displays information about all ports
on HOST7 of the Standard TCP/IP Port type:
PS C:\> Get-PrinterPort -ComputerName HOST7 | where Description -like "*TCP*"
Name ComputerName Description PortMonitor
---- ------------ ----------- -----------
172.16.11.55 HOST7 Standard TCP/IP Port TCPMON.DLL