Link to home
Start Free TrialLog in
Avatar of Tom Powers
Tom Powers

asked on

wmi VB Scripting

I created a vb script that pulls all Computers on network I need to see what computers are static and which ones are Dhcp I'm so close but Do While with a Loop is giving me fits. I just need this vb script to read entire list of computers and then for each one write computername and IPEnabled = True or IPEnabled =False. here is my vb script

Set objFSO=CreateObject("Scripting.FileSystemObject")


outFile="c:\computersDHCP.txt"
Set objFile = objFSO.CreateTextFile(outFile,True)

Const ForReading = 1
Set objFSOR = CreateObject("Scripting.FileSystemObject")
Set objTextFileR = objFSOR.OpenTextFile _
("computers2.txt", ForReading)
Do Until objTextFileR.AtEndOfStream
strComputer = objTextFileR.Readline
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\CIMV2") 
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM Win32_NetworkAdapterConfiguration Where IPEnabled = 'True'")

For Each objItem in colItems
    If objItem.DHCPEnabled = TRUE Then
       objFile.Write strComputer & " DHCP enabled" & vbCrLf
objFile.Close     
        Else
objFile.Write strComputer & " DHCP enabled" & vbCrLf
              
End If
     
 objTextFile.Close     
Next

Open in new window

Computers2.txt
ASKER CERTIFIED SOLUTION
Avatar of TheNautican
TheNautican

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tom Powers
Tom Powers

ASKER

Great solution Thanks Naut.