Collect Server Maintenance Information

This was the first real VBScript I used on the job. I wrote this while I held an intern position at an IT outsourcing company called Innovative Network Design (IND) Corporation in Parsippany, NJ. The reason I wrote it is simple, they kept assigning me to collect specific information from various client servers. So why keep doing it manually? I wrote this code and the employees actually still use it.

Project Overview:

Using VBScript I was able to come up with a way to create a file that shows administrators key information about a Windows Server 2003 machine. There is also a lot of error checking going on behind the scenes and a few things the script user must input before anything happens.

Key VBScript Concepts:

  • Ability to query WMI for various objects
  • Extensive error checking
  • Use of UNC (\\server\share) file paths to allow remote execution
  • Completely modular, all tasks are in their own procedure

User Input Required:

Upon starting the script it will ask you where you'd like to backup the Event Logs to along with your initials. The company I was working for did not have a standard place to back up the logs to so it had to be flexible. Also, as a standard practice we would append our initials to the end of the log file name.

Ask for a valid directory and check if it exists

' ask user for backup log location
Dim i
i = 0
Do While CheckFolderExists(usrFileLoc) = False
	If i = 0 Then
		usrFileLoc = InputBox _
			("Directory to backup Log files to:", _
			"Input Required")
		usrFileLoc = InputBox _
			("Invalid Directory..." & vbCrLf & _
			"Directory to backup Log files to:",  _
			"Input Required")
	End If
	i = i + 1

Ask the user for his/her initials

' ask user for initials
Do While strInitials = ""
	strInitials = InputBox("What are your initials?", _
		"Input Required")

Error Checking Capabilities:

The script will create an dictionary of all the available WMI objects available on the system and before trying to query each WMI object it checks if the WMI object exists in the dictionary. Then log the error to a second dictionary object. At the end of the script it will tell you what problems it encountered or tell you everything ran successfully. The below code shows an example of what is going on before trying to query WMI.

' check the dictionary objWMIClasses for "Win32_NTLogEvent"
If objWMIClasses.Exists("Win32_NTLogEvent") Then
     ' run the code to check event logs
End If

The User Interface:

The user interface is entirely command line based. This is used to show progress as the script runs. It can take some time to complete if there are a lot of logs on the system or a lot of partitions (it has to run disk analysis on each one) so this interface gives you a good idea about what is going on.

the user interface

When you see an "X" that means the item completed successfully while as a "!!" means there was an error while checking that individual item. When there is an error you will be shown more information at the end of the script as shown below.

output message

Output File:

The output file is in Rich Text Format (.rtf) for issues related to the company I was working for at the time. To take a look at a full example download an example output file.

Source Code and Read Me files:

Below you can obtain the actual script along with the read me file. The read me file contains a change log which shows my progress.

Download Source Code
Download README file

Watch the script in action:

All Information Gathered:
Here's a list of everything that is gathered

  • Operating System
    • Name
    • Version
    • Service Pack
  • CPU Info (listed per core)
    • Clock speed
    • Manufacture
    • Type
    • Current load
  • Memory Information
    • RAM slot number
    • Memory size
    • Speed
    • Type
  • Hard Drive Info
    • Model
    • Drive size
    • Drive type
    • Number of partitions
      • Volume name
      • Volume size
      • Cluster size
      • Used space
      • Free space
      • Percent free space
      • Total fragmentation
      • Disk Analysis defrag recommendation output
  • List of errors in the Device Manager
    • Error message and name
  • Parsing of all Event Logs on the system
    • Each unique error outputs the following
      • Total times this error occurred
      • Category
      • Computer Name
      • Event Code
      • Message
      • Record Number
      • Source Name
      • Time Written
      • Event Type
      • User
  • Anti-Virus information (if Symantec AV is installed)
    • Date last updated definitions
    • Parent Server
    • Client Group
    • Product Version
    • Scan Engine
  • Windows Updates available
    • Number of high, normal, and low priority available

Back to my projects