Solved

wmi VB Scripting

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

How our DevOps Teams Maximize Uptime

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

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
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 …
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…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

733 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