Retrieving System Information
Microsoft® Windows® 2000 Scripting Guide
Most computer management activities, including troubleshooting computer problems, installing new software, and applying Group Policy, require comprehensive information about how a computer has been configured. This information includes such things as the:
Operating system installed on a computer.
Amount of memory installed on a computer.
Amount of disk space available on a computer.
The System Information snap-in has long been the tool of choice for system administrators needing comprehensive information about a computer, the hardware installed on that computer, and the software running on that computer. The System Information snap-in and a sample of the kind of information it can return are shown in Figure 8.1.
Figure 8.1 System Information Snap-in
Although the System Information snap-in is a useful tool, it does have limitations that make it a less than optimal choice for performing inventories. In particular, this tool:
Is designed to work on a single computer at a time, and it works best when run against the local computer rather than a remote computer.
Cannot be automated or customized.
Does not lend itself to enterprise-wide retrieval and storage of computer information.
Does not allow for exporting data directly into a database.
Although it is possible to manually export the data from within System Information, the resulting text file uses a free-form style of formatting that makes it difficult to parse the information and save it to a database.
Does not allow you to customize data retrieval to meet your needs. In fact, the amount of data returned from System Information is often more than is needed for routine administrative tasks.
To overcome these limitations, system administrators have typically turned to third-party tools. Depending on your needs, however, you can save considerable cost by creating custom Windows Management Instrumentation (WMI) scripts that replicate the full functionality of the System Information snap-in. Using a WMI script provides a number of advantages over the System Information snap-in:
Scripts can be run against a single computer or against multiple computers.
Scripts can be used to automate data collection.
For example, a script can be scheduled to run on a group of computers at a specific date and time.
Scripts can be customized to return only the desired data.
Scripts can be customized to collect data not retrieved by System Information.
For example, although System Information can retrieve the name and version number of the operating system, it cannot retrieve more detailed information such as the set of hot fixes that have been applied to the computer.
Scripts can save data in a standard text file format (such as tab-delimited or comma-delimited), or directly to a database.
Table 8.1 lists the data fields found on the System Information Summary tab and the equivalent WMI classes and properties.
Table 8.1 System Information Fields and Equivalent WMI Classes and Properties
System Information Field |
WMI Class and Property |
---|---|
OS Name |
Win32_OperatingSystem.Name |
OS Version |
Win32_OperatingSystem.Version |
Service Pack |
Win32_OperatingSystem.ServicePackMajorVersion Win32_OperatingSystem.ServicePackMinorVersion |
OS Manufacturer |
Win32_OperatingSystem.Manufacturer |
System Name |
Win32_ComputerSystem.Name |
System Manufacturer |
Win32_ComputerSystem.Manufacturer |
System Model |
Win32_ComputerSystem.Model |
System Type |
Win32_Processor.Architecture |
Processor |
Win32_Processor.Description |
BIOS Version |
Win32_BIOS.Version |
Windows Directory |
Win32_OperatingSystem.WindowsDirectory |
Locale |
Win32_OperatingSystem.Locale |
Time Zone |
Win32_ComputerSystem.TimeZone |
Total Physical Memory |
Win32_ComputerSystem.PhysicalMemory |
Available Physical Memory |
Win32_OperatingSystem.FreePhysicalMemory |
Total Virtual Memory |
Win32_OperatingSystem.TotalVirtualMemory |
Available Virtual Memory |
Win32_OperatingSystem.AvailableVirtualMemory |
Page File Space |
Win32_OperatingSystem.SizeStoredInPagingFiles |
Scripting Steps
Listing 8.1 contains a script that retrieves the specified system information for a computer. To carry out this task, the script must perform the following steps:
Create a variable to specify the computer name.
Use a GetObject call to connect to the WMI namespace root\cimv2, and set the impersonation level to "impersonate."
Use the ExecQuery method to query the Win32_OperatingSystem class.
This query returns a collection consisting of all the operating systems installed on the computer.
For each item in the collection, echo the desired property values.
Repeat steps 3 and 4, substituting the other desired WMI classes.
Separate calls are required because WMI allows you to connect to only a single class at a time.
Listing 8.1 Retrieving System Information
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|