Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Gather Information about Domain PCs using WMI

0.00/5 (No votes)
24 May 2007 1  
A VBScript written to gather information about all domain workstations using WMI

Introduction

This VBScript enumerates information about domain PCs. The script prompts you to enter the distinguished name of your domain, then using WMI polls all available computer objects for hardware/software information. Logs are created to store computer information and recommended upgrades (based on memory).

Background

We use this script to gather hardware/software information along with the Dell service tag #'s for all new clients.

Using the Code

Enter the distinguished name of your domain in the format dc=your_domain,dc=com.

On error resume next

Const ADS_SCOPE_SUBTREE = 2
Set fso = CreateObject("Scripting.FileSystemObject")

set list = fso.CreateTextFile("./output.txt")
Set upgrade = fso.CreateTextFile("./upgrade.txt")

strDomainDn = InputBox("Enter the DN of your domain." & _
			vbCrLf & "(i.e. dc=domain,dc=com)")

If strDomainDn = "" Then
    WScript.Echo "Exiting!"
    WScript.Quit
End If

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
    "Select Name, Location from 'LDAP://" & strDomainDn & "' " _
        & "Where objectClass='computer'"  
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 

Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst

Do Until objRecordSet.EOF
    
    ' list.write "Computer Name: " & objRecordSet.Fields("Name").Value
    strComputer = objRecordSet.Fields("Name").Value
    
    Set objShell = CreateObject("WScript.Shell")
    strCommand = "%comspec% /c ping -n 3 -w 1000 " & strComputer & ""
    Set objExecObject = objShell.Exec(strCommand)

    Do While Not objExecObject.StdOut.AtEndOfStream
        strText = objExecObject.StdOut.ReadAll()
        If Instr(strText, "Reply") > 0 Then
            Set objWMIService = GetObject _
                ("winmgmts:\\" & strComputer & "\root\cimv2")
             Set colItems = objWMIService.ExecQuery _
                    ("Select * From Win32_OperatingSystem")  
            Set colItems2 = objWMIService.ExecQuery("Select * from Win32_BIOS",,48)
               ' list.write Err.Description
            Set colItems3 = objWMIService.ExecQuery_
			("Select * from Win32_ComputerSystem",,48)
            Set colItems4 = objWMIService.ExecQuery_
			("SELECT * FROM Win32_Processor", "WQL", _
                         	wbemFlagReturnImmediately + wbemFlagForwardOnly)

            For Each objItem in ColItems
                strOS = objItem.Caption
            Next
            
            For Each objItem in colItems2
                strDellTag = objItem.SerialNumber
                strManu = objItem.Manufacturer
            Next
    
            For Each objItem in colitems3
                strUserName = objItem.Username
                strModel = objItem.Model
                strRAM = objItem.TotalPhysicalMemory
                strTimeZone = (objItem.CurrentTimeZone / 60)
                strDayLightSavings = objItem.DaylightInEffect
            Next
        
            For Each objItem in colitems4
                strProcessor = objItem.Name
            Next
            
            If Err.Number > 0 then
                strErrorSystems =  strComputer & ", " & strErrorSystems 
            Else
                list.write "-----------------------------------------" & vbcrlf & vbcrlf
                list.write "Computer Name: " & strComputer & ", " & strUserName & vbcrlf 
                list.write "-----------------------------------------" & vbcrlf & vbcrlf
                list.write "Operating System: " & strOS & vbcrlf
                list.write "Current User: " & strUserName & vbcrlf
                list.write "::::" & vbcrlf
                list.write "Manufacturer: " & strManu & vbcrlf
                list.write "Model: " & strModel & vbcrlf
                list.write "Dell Service Tag: " & strDellTag & vbcrlf
                list.write "Processor type: " & strProcessor & vbcrlf
                list.write "RAM: " & strRAM & vbcrlf
                list.write "Time Zone: " & strTimeZone & vbcrlf
                list.write "Daylight Savings in effect: " & strDayLightSavings & vbcrlf
                list.write "----------------------------------------" & vbcrlf & vbCrLf
                memory = (strRam/1024)/1024
                memory = Int(memory)
                memory = memory + 2
                
                If strRam < 526454784 Then
                    upgrade.Write strComputer & " has only " & memory & _
			"MB of Ram!  We seriously recommend an upgrade!" _
			& vbCrLf & "Dell Service Tag (if Dell): " & strDellTag
                End If
            End If
                
            'flushes error code from the previous loop
            Err.Clear
       Else
             UnavailableSystems =  strComputer & ", " & UnavailableSystems
       End If
    Loop
    objRecordSet.MoveNext
Loop

list.write "The following systems were unavailable: " & UnavailableSystems & vbcrlf
list.write " " & vbcrlf & vbcrlf
list.write "The following systems were on, but returned an error: " & _
			strErrorSystems & vbcrlf

WScript.Echo "Done!"

Points of Interest

This script is pretty utilitarian.

History

  • Uploaded 5-24-07

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here