WMI Printer - Query
Introduction to Querying Printers with WMI
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.
Topics for WMI Printer
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
VBScript to List WMI Printer Properties
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.
From a WMI Perspective
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:
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
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.
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!
PowerShell Printer Example : Properties for Win32_Printer
# PowerShell cmdlet to investigate win32_printer properties
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
Summary of Querying Printer Properties
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
See more VBScript WMI examples: