Skip to content

Instantly share code, notes, and snippets.

@clly
Created May 29, 2012 22:00
Show Gist options
  • Save clly/2831066 to your computer and use it in GitHub Desktop.
Save clly/2831066 to your computer and use it in GitHub Desktop.
Set Windows DNS and IP addressing to use DHCP
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colNicConfigs = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
For Each obj in colNicConfigs
obj.SetDNSServerSearchOrder(null)
if not obj.DHCPEnabled Then
obj.EnableDHCP
End if
Next
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment