Script to "Obtain IP Automatically"

  • Thread starter Thread starter Joe
  • Start date Start date
J

Joe

Hey all,

I was wondering if anyone had a script to change the IP
settings on the computers from their, currently static
state, over to the "Obtain an IP address automatically"
state, as well as the Obtain DNS server address, to auto.

Basically we just setup our DHCP and I needed to see if I
could switch everyone over via AD to start logging onto
the DHCP server and get all their settings!

Much Appreciated,

Joe
 
A script would be hard because it is adapter-specific

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interf
aces\{ID of interface}\EnableDHCP=DWORD:1

--Shawn
This posting is provided "AS IS" with no warranties and confers no rights.
 
Joe said:
Hey all,

I was wondering if anyone had a script to change the IP
settings on the computers from their, currently static
state, over to the "Obtain an IP address automatically"
state, as well as the Obtain DNS server address, to auto.

Basically we just setup our DHCP and I needed to see if I
could switch everyone over via AD to start logging onto
the DHCP server and get all their settings!

Much Appreciated,

Joe

But if there is only 1 NIC...

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
'// Watch for line wrap here
Set colItems = objWMIService.ExecQuery("Select * from
Win32_NetworkAdapterConfiguration where IPEnabled = true")

'// Change to goDHCP() to set the machine to DHCP
goDHCP

Sub goDHCP()
For Each objItem In colItems

errEnable = objItem.EnableDHCP()
If errEnable = 0 Then
Wscript.Echo "DHCP has been enabled."
Else
Wscript.Echo "DHCP could not be enabled."
End If
Msgbox "setting DNS"
errDNS = objitem.SetDNSServerSearchOrder()
errDDNS = objItem.SetDynamicDNSRegistration
msgbox "DNS Set"
errRenew = objItem.RenewDHCPLease
msgbox "renew called"
If errRenew = 0 Then
Wscript.Echo "DHCP lease renewed."
Else
Wscript.Echo "DHCP lease could not be renewed." & err.number &
err.description
End If
Next
End Sub


--
Regards,

Michael Holzemer
No email replies please - reply in newsgroup

Learn script faster by searching here
http://www.microsoft.com/technet/treeview/default.asp?url=/technet/scriptcenter/default.asp
 
Whoa Mike - Impressive!
--Shawn
This posting is provided "AS IS" with no warranties and confers no rights.
 
It actually works on 2 NIC machines, I have a bunch of
nodes that have 2 NICs, though we only use 1 the second is
disabled. It updates the active first NIC just fine
though!

Many thanks for the script!

Joe
 
Back
Top