Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Changing Static to DHCP on multiple NICs

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,48585
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Changing Static to DHCP on multiple NICs
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Changing Static to DHCP on multiple NICs - 6/21/2007 5:04:20 AM   
  Wyvern


Posts: 11
Score: 0
Joined: 6/21/2007
Status: offline
I have a modified Microsoft Script that should set multiple workstations to DHCP by using a text file with a list of the workstation names.  However, something is wrong with it as it will only set the first machine in the list to DHCP, and appears to ignore the rest.  Anyone willing to point out the error would be welcome to chime in.

On Error Resume Next
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("Machines.txt", ForReading)
Do Until objTextFile.AtEndOfStream
   strComputer = objTextFile.Readline
  
Set objWMIService = GetObject("winmgmts:" _
   & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery _
   ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

For Each objNetCard In colNetCards
   errEnable = objNetCard.EnableDHCP()
Next
Loop
objTextFile.Close
Wscript.Echo "Script has completed"
 
 
Post #: 1
 
 RE: Changing Static to DHCP on multiple NICs - 6/21/2007 5:09:47 AM   
  LANlazy

 

Posts: 82
Score: 0
Joined: 4/11/2007
Status: offline
If you remove the On Error Resume Next what does it do?

(in reply to Wyvern)
 
 
Post #: 2
 
 RE: Changing Static to DHCP on multiple NICs - 6/21/2007 5:11:35 AM   
  LANlazy

 

Posts: 82
Score: 0
Joined: 4/11/2007
Status: offline
Try this line

strComputer = oipFile.ReadLine()

(in reply to Wyvern)
 
 
Post #: 3
 
 RE: Changing Static to DHCP on multiple NICs - 6/21/2007 8:15:05 AM   
  Wyvern


Posts: 11
Score: 0
Joined: 6/21/2007
Status: offline
Neither change affects it except to make the script hang when I changed it to say:
strComputer = oipFile.ReadLine()


(in reply to Wyvern)
 
 
Post #: 4
 
 RE: Changing Static to DHCP on multiple NICs - 6/21/2007 11:09:16 PM   
  mbouchard


Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
Is it possible that WMI is broken on the remote PC's or that you do not have admin rights?  Try reading something from the PC using FSO and see what you get.

_____________________________

Mike

For useful Scripting links see the Read Me First stickey!

Always remember Search is your friend.

(in reply to Wyvern)
 
 
Post #: 5
 
 RE: Changing Static to DHCP on multiple NICs - 6/21/2007 11:27:42 PM   
  LANlazy

 

Posts: 82
Score: 0
Joined: 4/11/2007
Status: offline
I have a couple of scripts that I use for remote administration.  But I dont use a Do Until/Loop.  Modify the script below that using a while not.  I also have a second On Error Resume Next.  I dont know why it makes a difference but it does.

On Error Resume Next
pstsearch = wscript.arguments(0)
set onet = createobject("wscript.network")
set ofs = createobject("scripting.filesystemobject")
set oipFile = ofs.opentextfile(pstsearch, 1, false)
if (Err.Number <> 0) then
    wscript.echo "Cannot open " & ipFile
    wscript.quit
end if
while not oipFile.atEndOfStream
    strComputer = oipFile.ReadLine()
    wscript.echo vbCrLf & "Connecting to " & strComputer & "..."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

if (Err.Number <> 0) then
            wscript.echo "Failed to connect to " & strComputer & "."
 On Error Resume Next
 
else
Set colFiles = objWMIService. _
   ExecQuery("Select Name from CIM_DataFile" _
       & " where Drive='c:' and Extension='pst'")
WScript.Echo "# of files found: " & colFiles.Count
For Each objFile in colFiles
   Wscript.Echo objFile.name
  
Next
End If
Wend
oipFile.close()

(in reply to Wyvern)
 
 
Post #: 6
 
 RE: Changing Static to DHCP on multiple NICs - 6/22/2007 2:55:11 AM   
  Wyvern


Posts: 11
Score: 0
Joined: 6/21/2007
Status: offline
I actually found that if I make sure that there are no blank spaces on any lines in the text file, this one will do the whole list. 

(in reply to Wyvern)
 
 
Post #: 7
 
 RE: Changing Static to DHCP on multiple NICs - 6/22/2007 2:57:34 AM   
  Wyvern


Posts: 11
Score: 0
Joined: 6/21/2007
Status: offline
I am a Domain admin, and all are member PCs.  It is possible that at times some of the workstations have WMI disabled, since our stinking PCTech department tends to load Dcombob on the workstations.  If only I could make them listen to reason!!

(in reply to LANlazy)
 
 
Post #: 8
 
 RE: Changing Static to DHCP on multiple NICs - 6/22/2007 4:22:11 AM   
  mcds99


Posts: 434
Score: 4
Joined: 2/28/2006
Status: online
while not oipFile.atEndOfStream

atEndOfStream == any blank line in the file.

_____________________________

Sam

Keep it Simple Make it Fun KiSMiF

(in reply to Wyvern)
 
 
Post #: 9
 
 RE: Changing Static to DHCP on multiple NICs - 6/22/2007 4:35:13 AM   
  Wyvern


Posts: 11
Score: 0
Joined: 6/21/2007
Status: offline
That is actually what I am using now though with a different name.

Do Until objTextFile.AtEndOfStream

The only thing screwing it up was a blank character at the end of the first line.

(in reply to mcds99)
 
 
Post #: 10
 
 RE: Changing Static to DHCP on multiple NICs - 6/22/2007 4:53:28 AM   
  ebgreen


Posts: 5035
Score: 31
Joined: 7/12/2005
Status: online
quote:

atEndOfStream == any blank line in the file.


What do you mean by a blank line?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to mcds99)
 
 
Post #: 11
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Changing Static to DHCP on multiple NICs Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts