As David mentioned, this is one of the good reasons to use DHCP in your
environment.
howver, to answer your question, there are a couple of ways to do this. You
can do it via registry import or WMI scripting. The Registry import is
somewhat harder because the GUID of the active NIC may NOT be the same
across all your clients. The DNS config is stored "NameServer" under the
following Reg Key:
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Tcpip\Parameters\Interfaces
\{GUID-of-the-ACTIVE-NIC}
NameServer will be blank IF the computer is using DHCP, otherwise it'll be
whatever the hardcoded IP is. As you can see, you can script a modification
of the "NameServer" values to whatever the new DNS IP should be.
Now, WMI is much easier because the Active NIC/NICS will always have the
"IPEnabled" property will always be true. This way you can correctly
determine the NIC to manipulate. I have used both the Registry and the WMI
methods in different situations, so I know they both work.
Here's a vbscript I use for this purpose.
Const ADS_SCOPE_SUBTREE = 2
Set objRoot = Getobject("GC://rootDSE")
strRootDomain = objRoot.Get("rootDomainNamingContext")
Wscript.Echo strRootDomain
'Wscript.Quit(0)
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
'if You want to query the computers in a ChildDomain
' "Select Name, Location from 'GC://DC=MyChildDomain," & strRootDomain &
"'" _
'if You want to query the computers in a SPECIFIC OU
' "Select Name, Location from 'GC://OU=MySpecificOU," & strRootDomain &
"'" _
'This will query all the computers in the root Domain
"Select Name, Location from 'GC://" & strRootDomain & "'" _
& "where objectClass='computer'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
ComputerName = objRecordSet.Fields("Name").Value
Call ChangeDNS_addy(ComputerName)
objRecordSet.MoveNext
Loop
Set objRecordSet = Nothing
Set objCommand = Nothing
Set objConnection = Nothing
Sub ChangeDNS_addy(ComputerName)
On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & ComputerName & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled =
True")
For Each objNetCard in colNetCards
arrDNSServers = Array("192.168.11.250", "192.168.11.251", "10.0.0.250")
objNetCard.SetDNSServerSearchOrder(arrDNSServers)
Next
Set colNetCards = Nothing
Set objWMIService = Nothing
End Sub
HTH
Deji