Previous Section Table of Contents Next Section

Collecting System Information

Software like Microsoft Systems Management Server (SMS) does a great job of collecting information from all of the computers in your environment. However, it's an expensive, complicated product, and sometimes you might just need a quick-and-dirty means of collecting the same information. This script is a great starting point for an inventory collection system that you can make a part of your users' logon scripts.

graphics/arrow.gif Collecting System Information

Listing 30.3 shows how a WMI script can be used to inventory information from a computer. For example, you could modify this script to run against multiple machines at once, letting you know what servers are running particular types of hardware.

Listing 30.3. CollectSysInfo.vbs. This script inventories a computer and displays the information.

Set oSystemSet = _

GetObject("winmgmts:").InstancesOf("Win32_ComputerSystem")



For Each oSystem in oSystemSet

 system_name = oSystem.Caption 

 system_type = oSystem.SystemType

 system_mftr = oSystem.Manufacturer

 system_model = oSystem.Model

Next

Set oProcSet = _

GetObject("winmgmts:").InstancesOf("Win32_Processor")



For Each oSystem in oProcSet

 proc_desc = oSystem.Caption 

 proc_mftr = oSystem.Manufacturer

 proc_mhz = oSystem.CurrentClockSpeed

Next



Set oBiosSet = _

 GetObject("winmgmts:").InstancesOf("Win32_BIOS")



For Each oSystem in oBiosSet

      bios_info = oSystem.Version

Next



Set oZoneSet = _

 GetObject("winmgmts:").InstancesOf("Win32_TimeZone")



For Each oSystem in oZoneSet

      loc_timezone = oSystem.StandardName

Next



Set oOSSet = _

 GetObject("winmgmts:").InstancesOf("Win32_OperatingSystem")



For Each oSystem in oOSSet

 os_name = oSystem.Caption

 os_version = oSystem.Version

 os_mftr = oSystem.Manufacturer

 os_build = oSystem.BuildNumber

 os_dir = oSystem.WindowsDirectory

 os_locale = oSystem.Locale

 os_totalmem = oSystem.TotalVisibleMemorySize

 os_freemem = oSystem.FreePhysicalMemory

 os_totalvirmem = oSystem.TotalVirtualMemorySize

 os_freevirmem = oSystem.FreeVirtualMemory

 os_pagefilesize = oSystem.SizeStoredInPagingFiles

Next



sMsg = ("OS Name:  " & os_name & Chr(10))

sMsg = sMsg & _

 ("Version:  " & os_version & " Build " & os_build & _

 Chr(10))

sMsg = sMsg & _

 ("OS Manufacturer:  " & os_mftr & Chr(10))

sMsg = sMsg & _

 ("oSystem Name:  " & system_name & Chr(10))

sMsg = sMsg & _

 ("oSystem Manufacturer:  " & system_mftr & Chr(10))

sMsg = sMsg & _

 ("oSystem Model:  " & system_model & Chr(10))

sMsg = sMsg & _

 ("oSystem Type:  " & system_type & Chr(10))

sMsg = sMsg & _

 ("Processor:  " & proc_desc & " " & proc_mftr & _

 " ~" & proc_mhz & "Mhz" & Chr(10))

sMsg = sMsg & _

 ("BIOS Version:  " & bios_info & Chr(10))

sMsg = sMsg & _ 

("Windows Directory:  " & os_dir & Chr(10))

sMsg = sMsg & _

 ("Locale:  " & os_locale & Chr(10))  

sMsg = sMsg & _ 

("Time Zone:  " & loc_timezone & Chr(10))

sMsg = sMsg & _ 

("Total Physical Memory:  " & os_totalmem & "KB" & _

 Chr(10))

sMsg = sMsg & _

 ("Available Physical Memory:  " & os_freemem & "KB" & _

 Chr(10))

sMsg = sMsg & _ 

("Total Virtual Memory:  " & os_totalvirmem & "KB" & _

 Chr(10))

sMsg = sMsg & _

 ("Available Virtual Memory:  " & _

 os_freevirmem & "KB" & Chr(10))

sMsg = sMsg & _

 ("Page File Space : " & os_pagefilesize & "KB" & _

 Chr(10))



MsgBox sMsg, 0,"System Summary Information"

This script is ready to run as-is on any system that supports WMI. Right now, the script is programmed to display its information in a message box. However, if you want to collect remote computer information, you could make this script part of a logon script and rewrite it to save its information to a file or database located on a file server. After all of your users log on and run the script, you'll have a complete central inventory of your computers!

graphics/arrow.gif Collecting System Information-Explained

To save space, I've left out the variable declarations in this script. That's normally a poor programming practice, but I hope you'll forgive me in light of the length of the script. Rather than declaring variables, this script jumps right in by using WMI to connect to the local management provider. You can learn more about WMI starting in Chapter 17.


Set oSystemSet = _

GetObject("winmgmts:").InstancesOf("Win32_ComputerSystem")

Next, I loop through each system instance that WMI found and retrieve its caption, system type, manufacturer, and model. Normally, there will only be one of these per computer. However, the WMI specification supports multiple "machines within a machine," so to speak, and that's why I've created a loop.


For Each oSystem in oSystemSet

 system_name = oSystem.Caption 

 system_type = oSystem.SystemType

 system_mftr = oSystem.Manufacturer

 system_model = oSystem.Model

Next

Processors are next, and I save their caption, manufacturer, and clock speed.


Set oProcSet = _

GetObject("winmgmts:").InstancesOf("Win32_Processor")



For Each oSystem in oProcSet

 proc_desc = oSystem.Caption 

 proc_mftr = oSystem.Manufacturer

 proc_mhz = oSystem.CurrentClockSpeed

Next

Now for the BIOS; I just retrieve the version.


Set oBiosSet = _

 GetObject("winmgmts:").InstancesOf("Win32_BIOS")



For Each oSystem in oBiosSet

      bios_info = oSystem.Version

Next

It might be useful to see which time zone your computers are configured for. Remember that some applications use time stamps for auditing purposes; having all of your computers in one time zone (at least, the ones that really are in the same time zone) makes that auditing information more accurate.

NOTE

Time zones don't affect domain operations, which all use Universal (Greenwich) time.



Set oZoneSet = _

 GetObject("winmgmts:").InstancesOf("Win32_TimeZone")



For Each oSystem in oZoneSet

      loc_timezone = oSystem.StandardName

Next

Next, I query a bunch of information about the operating system, including its name, version, manufacturer, build number, the location of the Windows folder, the language locale, and stats on the system's memory configuration.


Set oOSSet = _

 GetObject("winmgmts:").InstancesOf("Win32_OperatingSystem")



For Each oSystem in oOSSet

 os_name = oSystem.Caption

 os_version = oSystem.Version

 os_mftr = oSystem.Manufacturer

 os_build = oSystem.BuildNumber

 os_dir = oSystem.WindowsDirectory

 os_locale = oSystem.Locale

 os_totalmem = oSystem.TotalVisibleMemorySize

 os_freemem = oSystem.FreePhysicalMemory

 os_totalvirmem = oSystem.TotalVirtualMemorySize

 os_freevirmem = oSystem.FreeVirtualMemory

 os_pagefilesize = oSystem.SizeStoredInPagingFiles

Next

Now, I format all of the information I've collected into a string variable.


sMsg = ("OS Name:  " & os_name & Chr(10))

sMsg = sMsg & _

 ("Version:  " & os_version & " Build " & os_build & _

 Chr(10))

sMsg = sMsg & _

 ("OS Manufacturer:  " & os_mftr & Chr(10))

sMsg = sMsg & _

 ("oSystem Name:  " & system_name & Chr(10))

sMsg = sMsg & _

 ("oSystem Manufacturer:  " & system_mftr & Chr(10))

sMsg = sMsg & _

 ("oSystem Model:  " & system_model & Chr(10))

sMsg = sMsg & _

 ("oSystem Type:  " & system_type & Chr(10))

sMsg = sMsg & _

 ("Processor:  " & proc_desc & " " & proc_mftr & _

 " ~" & proc_mhz & "Mhz" & Chr(10))

sMsg = sMsg & _

 ("BIOS Version:  " & bios_info & Chr(10))

sMsg = sMsg & _ 

("Windows Directory:  " & os_dir & Chr(10))

sMsg = sMsg & _

 ("Locale:  " & os_locale & Chr(10))  

sMsg = sMsg & _ 

("Time Zone:  " & loc_timezone & Chr(10))

sMsg = sMsg & _ 

("Total Physical Memory:  " & os_totalmem & "KB" & _

 Chr(10))

sMsg = sMsg & _

 ("Available Physical Memory:  " & os_freemem & "KB" & _

 Chr(10))

sMsg = sMsg & _ 

("Total Virtual Memory:  " & os_totalvirmem & "KB" & _

 Chr(10))

sMsg = sMsg & _

 ("Available Virtual Memory:  " & _

 os_freevirmem & "KB" & Chr(10))

sMsg = sMsg & _

 ("Page File Space : " & os_pagefilesize & "KB" & _

 Chr(10))

Finally, I finish by using a message box to display the information. As I pointed out earlier, you could modify this to write the information to a central file or database.


'display results

MsgBox sMsg, 0,"System Summary Information"

This script is a great example of how WMI can save you time and effort when you need to perform enterprise-wide operations in a limited amount of time or on a limited budget. It is not SMS, but it's free, easy to write yourself, and can help solve a similar problem.

    Previous Section Table of Contents Next Section