> We have 2000 computers in our network all of which are using Static IP
> addresses. We are currently migrating to a new AD domain and want an
> automated way of changing the DNS Server IP address on these workstations.
> While i can use netsh command to achieve that i need to know the interface id
> or name to achieve that.
>
> So basically i am looking for a script which can take input of workstation
> ipaddress from a txt file and provide the interface name and id in an output
> file.
I'm not a scripting guru, but here's one example I got from a friend
years ago. Test it out on your own workstation. You can use the psexec
utility (from PSTools free from Microsoft) to remotely run it on all
machine, or set it in a logon script.
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
======
Also...
======
The script below is to set all adapters to DHCP:
(from:
http://www.microsoft.com/technet/com.../scrnet03.mspx)
================================
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\cimv2") Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where
IPEnabled=TRUE") For Each objNetAdapter In colNetAdapters
arrDNSServers = Array()
objNetadapter.SetDNSServerSearchOrder(arrDNSServer s)
errEnable = objNetAdapter.EnableDHCP()
If errEnable = 0 Then
Wscript.Echo "DHCP has been enabled."
Else
Wscript.Echo "DHCP could not be enabled."
End If
Next
================================
--
Ace
This posting is provided "AS-IS" with no warranties or guarantees and
confers no rights.
Please reply back to the newsgroup or forum for collaboration benefit
among responding engineers, and to help others benefit from your
resolution.
Ace Fekay, MCT, MCITP EA, MCTS Windows 2008 & Exchange 2007, MCSE &
MCSA 2003/2000, MCSA Messaging 2003
Microsoft Certified Trainer
For urgent issues, please contact Microsoft PSS directly. Please check
http://support.microsoft.com for regional support phone numbers.