OK, so you have just rebuilt your DNS/WINS server and it has a new IP address, now you have to log into every server that you gave a static address to and update the DNS/WINS…or do you ?
Not anymore, thanks to FatBeard
The following powershell script will do it for you by using PowerShell, you only need PowerShell on the machine you are running it from, not the servers you are changing as this is done through WMI. Even reads the server name entries from a text file !
function Set-DNSWINS {
#Get NICS via WMI
$NICs = Get-WmiObject ‘
-Class Win32_NetworkAdapterConfiguration ‘
–ComputerName $_ ‘
-Filter “IPEnabled=TRUE”
foreach($NIC in $NICs) {
$DNSServers = “12.34.5.67”,”76.54.3.21″
$NIC.SetDNSServerSearchOrder($DNSServers)
$NIC.SetDynamicDNSRegistration(“TRUE”)
$NIC.SetWINSServer(“12.345.67.890”, “12.345.67.891”)
}
}
function Get-FileName {
$computer = Read-Host “Filename of computer names?”
return $computer
}
$f = Get-FileName
Get-Content $f foreach {Set-DNSWINS}
Please share sample for this WINS ip change.
Make sure to change this section:
$f = Get-FileName
Get-Content $f foreach {Set-DNSWINS}
to this (note the | before foreach ***IMPORTANT***):
$f = Get-FileName
Get-Content $f | foreach {Set-DNSWINS}
ARRGHHH, I am so close, why does the script keep asking me for a parameter everytime i run the thing?????
function Set-DNSWINS {
#Get NICS via WMI
$NICs = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName $_ | where{$_.IPAddress -like “*10.201.8.*”}
foreach($NIC in $NICs) {
$DNSServers = “10.201.8.98”,”10.201.158.22″
$NIC.SetDNSServerSearchOrder($DNSServers)
$NIC.SetDynamicDNSRegistration(“TRUE”)
$NIC.SetWINSServer(“10.201.8.98″,”10.201.158.22”)
}
}
function Get-FileName {
$computer = Read-Host c:\TEMP\servers.txt
return $computer
}
$f = Get-FileName
Get-Content $f foreach {Set-DNSWINS}
I just finished running this script on our 150+ servers and within minutes they all had the new DNS/WINS entries! Thanks so much Virtu-Al for all your help in customizing this script for our environment and saving us loads of administrative time!!
Thanks,
Greg