Force DHCP on a PC set for Static IP

We are currently redesigning our network at Williams & Fudge with the help of the guys at eGroup.

One of my responsibilities before we start converting to vlans (Yes, we have a flat network right now) is to convert all of our PCs and VoIP phones to DHCP.  With 265 PCs, that is not something I want to do manually.  And of course, my users are not capable of doing it themselves.

So here’s a handy VBS script I found over on the technet community at this link.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\" & strComputer & "rootcimv2")

Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

For Each objNetAdapter In colNetAdapters
errEnable = objNetAdapter.EnableDHCP()
Next

*NOTE: This only works on Windows XP, Server 2000, and Server 2003.*

UPDATE – Well after the 5-hour energy drinks were had, we realized the script above doesn’t change from static DNS to dynamic DNS.  Here’s the script for that:

strComputer = "."

Set objWMIService = GetObject("winmgmts:\" & strComputer & "rootcimv2")

Set colNetCards = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")

For Each objNetCard in colNetCards
arrDNSServers = Array()
objNetCard.SetDNSServerSearchOrder(arrDNSServers)
Next

———————————————-

This blog was originally posted on http://www.egroup-us.com/?p=3171. Same Author. Different Site.

No comments yet.

Leave a Reply