Because I had a mix 23/28/28r2/12 servers decided wmi was the path forward + powershell.
Script in 3 parts:
- check all the servers to see if hard code to old DC
- Update the DHCP server options on all authorised DHCP servers
- Purge any scope with setting for old DC to use the server option
#StartHere :)
$OUName= 'OU=Servers,DC=KoolKids'
$TheComputers = Get-ADComputer -filter * -searchbase $OUName
$results = @()
Foreach ($server in $TheComputers) {
if(Test-Connection $server.name -Count 1 -quiet){
$NICs = Get-WMIObject Win32_NetworkAdapterConfiguration -computername $server.name| where{$_.IPEnabled -eq “TRUE”}
Foreach($NIC in $NICs) {
$FTW=$NIC.DNSServerSearchOrder
$FTW =[String]$FTW
# write-host $FTW
If ($FTW.contains("10.10.3.1")) {
$results += New-Object PSObject -Property @{
Server = $server.name
DNS = $FTW
}
#update the DNS Server for this NIC
$DNSServers = "172.18.0.10","172.18.0.11"
$NIC.SetDNSServerSearchOrder($DNSServers)
}
}
}
}
#set the default server scope options to correct setting
foreach ($dhcpserver in Get-DhcpServerInDC){
if(Test-Connection $dhcpserver.DNSName -Count 1 -Quiet){
#Remarked out so that all active DHCP servers get updated!
#If ($FTW.contains("10.10.3.1")) {
$FixScope=[System.Net.Dns]::GetHostAddresses($dhcpserver.DNSName).IPAddressToString, "172.18.0.10", "172.18.0.11"
Set-DhcpServerv4OptionValue -ComputerName $dhcpserver.DNSName -OptionId 6 -Value $FixScope
#}
}
}
#clear out the scope options
# WARNING SERVER OPTIONS MUST HAVE a SETTING OR BAD THINGS HAPPEN
foreach ($dhcpserver in Get-DhcpServerInDC){
foreach ($TheScope in (Get-dhcpserverv4scope -computername $dhcpserver.DnsName)){
$target=$null
$Target=Get-DhcpServerv4OptionValue -ComputerName $dhcpserver.DNSName -OptionId 6 -ScopeId $TheScope.ScopeId -ErrorAction SilentlyContinue
$Target=[String]$target.Value
If ($Target.contains("10.10.3.1")) {
Remove-DhcpServerv4OptionValue -ComputerName $dhcpserver.DNSName -OptionId 6 -ScopeId $TheScope.ScopeId
}
}
}
No comments:
Post a Comment