Click here to Skip to main content
15,881,812 members
Articles / Programming Languages / VBScript

Gather Information about Domain PCs using WMI

Rate me:
Please Sign up or sign in to vote.
4.56/5 (5 votes)
24 May 2007CPOL 48.3K   588   18   3
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.

VBScript
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionOutput to Excel Pin
Gomtu13-Jun-07 6:31
Gomtu13-Jun-07 6:31 
GeneralGood... A bit buggy... Pin
irrdev24-May-07 17:40
irrdev24-May-07 17:40 
This is a good app, but there are a few bugs. I got a MAJOR one. To demonstrate what I mean, start the script and in the input window, type:

dc=localhost

Sit back and watch what happens. You'll quickly see what I mean.;)


GeneralRe: Good... A bit buggy... Pin
xExTxCx25-May-07 5:52
xExTxCx25-May-07 5:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.