Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

wmi VB Scripting

Posted on 2014-01-31
2
Medium Priority
?
279 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 8

Accepted Solution

by:
TheNautican earned 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
The viewer will learn how to count occurrences of each item in an array.
Starting up a Project
Suggested Courses

604 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