Solved

wmi VB Scripting

Posted on 2014-01-31
2
260 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

A short article about problems I had with the new location API and permissions in Marshmallow
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn how to dynamically set the form action using jQuery.

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now