This WMI script offers a variety of solutions to printer problems on a
Windows Network. WMI provides and impressive range of eight classes of printer object so it is possible to query any aspect of a printer. To let you into a secret, as I researched the Win32_Printer properties I found
printer attributes that I did not even know existed.
Printers and Print Devices, give more than their fair share of administrative problems. While the most likely solution is to add paper or toner; however, you may want to run a WMI script just in case there is a configuration setting that would help prevent the problem
re-occurring. As with most WMI scripts, the key is identifying the best Win32_Classes to query. In the case of printer, there are eight Win32 objects to choose from, so if at first you don't succeed try a
different class of object.
Example 1 - WMI Query Win32_Printer
I am impressed by the sheer number of properties, from obvious items such as share name and printer driver to little known Horizontal Resolution.
Prerequisites for
Your Printer WMI Script
The only pre-requisite is that you have a printer
attached to the machine where you run the script. Be aware, there may be a delay while the script checks all possible printer ports.
Instructions for Listing Processes WMI Script
Copy and paste the example script below into notepad or a VBScript editor.
Decide which machine on your network to interrogate and then change line 9: strComputer = "." to the name of that machine.
Save the file with a .vbs extension, for example: PrinterWMI.vbs
Double click PrinterWMI.vbs and check the number of printers and their properties.
VBScript to List WMI Printer Properties
' PrinterWMI.vbs ' Sample WMI Printer VBScript to interrogate properties ' Author Guy Thomas http://computerperformance.co.uk/ ' Version 2.3
- December 2010 ' -----------------------------------------------' Option Explicit Dim objWMIService, objItem, colItems, strComputer, intPrinters
strComputer ="." intPrinters
= 1
' -------------------------------------------- ' Pure WMI Section Set objWMIService = GetObject _ ("winmgmts:\\" & strComputer & "\root\CIMV2") Set colItems = objWMIService.ExecQuery _
("SELECT * FROM Win32_Printer")
sub Wait() If strComputer = "." then strComputer = "Local Host" else strComputer = strComputer
end if
WScript.Echo "Wait 2 mins for " & strComputer _ & " to enumerate printers"
End Sub
WScript.Quit
' End of Sample Printer VBScript
Footnote: Harry Stein kindly wrote in pointing
out that you get a better formatting result with VbCrLf,
rather than plain VbCr.
Windows 8 printer troubleshooting.
Guy
Recommends: WMI Monitor and It's Free!
Windows Management Instrumentation (WMI) is one of the hidden
treasures of Microsoft's operating systems. Fortunately, SolarWinds
have created a
Free WMI Monitor so that you can discover these gems of performance
information, and thus improve your scripts.
Take the guess work out of which WMI counters to use when scripting the
operating system, Active Directory or Exchange Server. Give this WMI monitor a
try - it's free.
1) If you are new to WMI then you will soon appreciate that all WMI scripts begin by
instructing winmgmts to access the root of the CIM library,
here is the command: Set objWMIService = GetObject("winmgmts:"
& strComputer & "\root\cimv2")
2) If you
have already looked at WMI scripts, then you will know the importance of Win32_Service and objItem.name.
3) Set colProcess = objWMIService.ExecQuery _ is a standard WMI phrase to prepare for the WQL command: Select * from Win32_Printer ". The part we are particularly interested in is
_Printer.
WMI has eight different types of printer object, we need to query the Printer component and not the PrinterController or PrinterDriver.
See also SolarWinds SNMP
enabler.
From a VBScript
Perspective
4) What makes scripting so powerful is the
speed with which VBScript
loops through an array of properties, in this instance the loop is controlled by: For Each....In... Next.
5) In this script I have added a sub routine called sub Wait(). In addition to
introducing you to the syntax of the sub routine, I wanted to put the extra cosmetic detail at the end of the script.
6) It is also possible to output the WMI information not to
the screen but to a file. VBScript has all the tools you need to create a file and write a service on each line. Writing to text files with FSO is covered in other VBScripts.
Guy
Recommends: The Free Config Generator
SolarWinds' Config Generator is a free tool, which puts you in charge of
controlling changes to network routers and other SNMP devices.
Boost your network performance by activating network device features
you've already paid for.
Guy says that for newbies the biggest benefit of this free tool is that
it will provide the impetus for you to learn more about configuring the SNMP
service with its 'Traps' and 'Communities'. Try Config Generator now - it's
free!
Printers and Print Devices, give more than their fair share of administrative problems. As with most WMI scripts, the key is identifying the best Win32_Classes to query. In the case of printer, there are eight Win32 objects to choose from, so if at first you don't succeed try a
different class of object.
If you like this page then please share it with your friends
Windows Management Instrumentation (WMI) is
most useful for PowerShell scripting.
SolarWinds
have produced this
Free WMI Monitor to take the guess work out of which
WMI counters to use for applications like Microsoft Active Directory,
SQL or Exchange Server.