Click here to Skip to main content
6,295,667 members and growing! (13,082 online)
Email Password   helpLost your password?
Languages » VBScript » General     Intermediate License: The Code Project Open License (CPOL)

Gather information about domain pc's using WMI.

By xExTxCx

A VBScript written to gather information about all domain workstations using WMI.
VBScript, Windows, Visual Studio, Architect, Dev, Design
Posted:24 May 2007
Views:14,420
Bookmarked:14 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
4 votes for this article.
Popularity: 2.67 Rating: 4.43 out of 5

1

2

3
1 vote, 25.0%
4
3 votes, 75.0%
5

Introduction

VBScript to enumerate information about domain pc's. 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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

xExTxCx


Member

Occupation: Systems Engineer
Company: ETC
Location: United States United States

Other popular VBScript articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 3 of 3 (Total in Forum: 3) (Refresh)FirstPrevNext
QuestionOutput to Excel PinmemberGomtu7:31 13 Jun '07  
GeneralGood... A bit buggy... Pinmemberirrdev18:40 24 May '07  
GeneralRe: Good... A bit buggy... PinmemberxExTxCx6:52 25 May '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 24 May 2007
Editor:
Copyright 2007 by xExTxCx
Everything else Copyright © CodeProject, 1999-2009
Web13 | Advertise on the Code Project