Solved

wmi VB Scripting

Posted on 2014-01-31
2
264 Views
Last Modified: 2014-02-04
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
0
Comment
Question by:powerztom
2 Comments
 
LVL 8

Accepted Solution

by:
TheNautican earned 500 total points
ID: 39826378
Powerztom - I think you have a few words mixed up here. You're query uses a WHERE clause to only return items that are " IPEnabled = 'True' " So there is no way to get ones that are false with this. I'm going to assume that what you really want is a list of computers and either "DHCP enabled" or "DHCP disabled". If so just change the part after your else statement like so

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


Regards,
-Naut
0
 

Author Closing Comment

by:powerztom
ID: 39832435
Great solution Thanks Naut.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Do Psexec queries install files on remote computers 6 62
Apps blocked by Java 9 79
Regular Expression Calculator Tester 2 73
printf performancy 11 42
A short article about problems I had with the new location API and permissions in Marshmallow
This is about my first experience with programming Arduino.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question