From the dawn of computing, printers have given more problems than any other
hardware. PowerShell is not the magic bullet to cure all your printer
ills, but using PowerShell makes it easier to interrogate printers than using
VBScript.
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. The secret of this week's
scripts is the ease with which PowerShell exploits WMI (Windows
Management Instrumentation) to provide information about your printers.
This Week's Mission
This week's mission is to get you started creating PowerShell scripts to
reveal a printer's properties and values:
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 PowerShell cmdlets employ WMI to interrogate computer objects such
as printers. As you may already know, get-WmiObject opens up a whole world
of system objects; all we need to do is identify the Printer class of objects. The point of this initial research is to answer the question, 'How did Guy
know to use the class Win32_Printer?'
The extra feature of Example 2 is the array. The idea is to create a
list; in this case computers on your network, then loop the particular code to
interrogate each computer in turn. As a preliminary step, amend the
variable $arrayComp to hold the names of real servers on your network. Pay
close attention to the speech marks and comma(s).
# PowerShell Array to List Printers # Author: Guy Thomas # Version 1.3
June 2008 tested on PowerShell v 1.0
Note 1: Use of -notMatch. "__" needs the star, hence "__*".
Note 2: By assigning the output to a variable, we can count the number of matching
properties.
Note 3: The tiny backtick (`) is useful for explaining to
PowerShell that the same command continues on the next line.
Note 4: Here is a more longwinded alternative to using the .count
property:
| where {if ($_.name -notmatch "__*") {$i++}}
If you are looking for handy network utilities, try some of the free downloads at
Tools4Ever
Summary of PowerShell Printers
PowerShell can extract information about your printers.
You can 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. I have used the printer
examples to learn about WMI classes and also as a vehicle to create an
array.
*
Guy
Recommends: Orion's NPM - Network Performance Monitor
Orion's performance monitor is designed for detecting network outages.
A network-centric
view make it easy to see what's working, and what needs your attention.
This utility guides you through troubleshooting by indicating whether the
root cause is faulty equipment or resource overload.