Retrieving and Displaying Properties of a Managed Resource
Microsoft® Windows® 2000 Scripting Guide
WMI is perhaps best suited for returning information about a computer; there are literally hundreds of WMI classes that provide information on everything from the services installed on a computer to the events recorded in the event logs to attached peripherals such as printers, monitors, and disk drives.
The amount - and variety - of information that can be returned by using WMI is, in itself, enough to make scripting an important tool for system administration. What makes the technology even more valuable, however, is the fact that the same basic approach can be used to return information regardless of the source. For example, the script template shown in Listing 6.23 returns information about the services installed on a computer. However, this template can easily be adapted to return information about any other managed resource on the computer.
Listing 6.23 Template for Retrieving and Displaying Resource Properties
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
To use this template with other WMI classes:
Set the value of strClassName to the appropriate WMI class.
If necessary, set the value of strNamespace to the appropriate WMI namespace.
Replace the statements within the For Each loop that echo the properties and their values. Remove the following lines and replace them with the appropriate lines of code for the property values being displayed.
Wscript.Echo "Caption " & objInstance.Caption Wscript.Echo "Description " & objInstance.Description