Skip to content

Instantly share code, notes, and snippets.

@nshores
Last active April 20, 2020 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nshores/7f28292a693d4c92d19c909c6999cfbc to your computer and use it in GitHub Desktop.
Save nshores/7f28292a693d4c92d19c909c6999cfbc to your computer and use it in GitHub Desktop.
failover dns
#run on med7 dc (local)
$zonename = "healthcare.local"
$ip_table = @{
M7FS = "10.1.100.30";
M7KDM = "10.1.100.7";
M7DTS = "10.1.100.6";
M7KESM = "10.1.100.8";
TS2 = "10.1.100.37";
M7APP = "10.1.100.5";
M7DB = "10.1.100.4"
}
$orig_table = @{
M7FS = "10.1.1.30";
M7KDM = "10.1.1.7";
M7DTS = "10.1.1.6;";
M7KESM = "10.1.1.8";
TS2 = "10.1.1.37";
M7APP = "10.1.1.5";
M7DB = "10.1.1.4"
}
&"/Users/nshores/Scripts/azure/azure-docs-powershell-samples/azure-migrate/migrate-at-scale-with-site-recovery/asr_testmigration.ps1 -CsvFilePath input_template.csv"
#update
foreach ($key in $ip_table.keys){
$OldObj = Get-DnsServerResourceRecord -Name $key -ZoneName $zonename
write-host "Old Object : $($oldobj.hostname) $($oldobj.RecordData.IPv4Address)"
$NewObj = $OldObj.Clone()
$newobj.RecordData.IPv4Address = "$($ip_table.$key)"
write-host "New Object : $($newobj.hostname) $($newobj.RecordData.IPv4Address)"
Set-DnsServerResourceRecord -NewInputObject $NewObj -OldInputObject $OldObj -ZoneName $zonename -PassThru
}
#replicate dns
Invoke-Command -ComputerName "m7-az-dc" -ScriptBlock {
& 'C:\Windows\System32\repadmin.exe' /syncall
}
#rollback
foreach ($key in $orig_table.keys){
$OldObj = Get-DnsServerResourceRecord -Name $key -ZoneName $zonename
write-host "Old Object : $($oldobj.hostname) $($oldobj.RecordData.IPv4Address)"
$NewObj = $OldObj.Clone()
$newobj.RecordData.IPv4Address = "$($ip_table.$key)"
write-host "New Object : $($newobj.hostname) $($newobj.RecordData.IPv4Address)"
Set-DnsServerResourceRecord -NewInputObject $NewObj -OldInputObject $OldObj -ZoneName $zonename -PassThru
}
#replicate dns
Invoke-Command -ComputerName "m7-az-dc" -ScriptBlock {
& 'C:\Windows\System32\repadmin.exe' /syncall
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment