I will show you how to use PowerShell to extract information about your printers.
We will create a script which not only lists the printers, but also
reveals their properties. For example, the printer's sharename,
driver, status and 90 other properties.
Despite being one of the first devices to be 'plug and play', printers
still give more than their fair share of problems. One clue of
trouble ahead is the large number of adjectives to qualify the
context of the word printer, for example, driver, device, default,
network and share. All this means is that printers provide rich
pickings for writing good PowerShell cmdlets. Here are possible
tasks for a printer script:
List all the printers on your server.
Trawl the network and list the printers on named servers.
Output the list of printers to a file.
Investigate additional WMI classes for use with printers.
Many of these printer cmdlets employ WMI to interrogate computer objects such
as printers. As you may know, get-WmiObject opens up a whole world of
system objects, which you can then use powershell to read their values.
The point of this initial research is to answer the question, 'How did Guy
know to use the class Win32_Printer?'
Instructions
If you have not used PowerShell before, here are step-by-step
instructions to execute commands.
Else, just rely on the trusty copy and paste method.
# PowerShell to list WMI Printer
Objects # Author: Guy Thomas # Version 1.2
June 2008 tested on PowerShell v 1.0
get-WmiObject -list | where {$_.name -match "Printer"}
Note 1: In addition to Win32_printer (featured below) there
is a class for TCP/IP printing: Win32_TCPIPPrinterPort.
Note 1: You must edit the value for $PrinterPath to
reflect a computer on your network.
Note 2: This PowerShell script does not use WmiObject
with its Win32 class, but instead it uses:
New-Object -com WScript.Network.
Note 3: Troubleshooting There should be no space
before the bracket, this mistake caused me some head-scratching, until I
realized that for once there was no spelling mistake in
AddWindowsPrinterConnection, just an unwanted space:
$net.AddWindowsPrinterConnection ($PrinterPath)
Summary of PowerShell and
Printers
Ever since I can remember, printers give more problems than any other
hardware. PowerShell is not the magic bullet to cure all your printer
problems, however, PowerShell makes it easier to configure printers than using
the same commands in VBScript.
Please write in if you see errors of any kind. Please report any factual mistakes, grammatical errors or broken links, I will be happy to not only to correct the fault, but also to give you credit.