Created
September 29, 2020 01:46
-
-
Save rwasef1830/3f2cf9c0c799e39d7b9d9579d72e3b18 to your computer and use it in GitHub Desktop.
Update Windows DNS Server A record IPs in all Zones
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
[Parameter(Mandatory=$true)][string] $oldIp, | |
[Parameter(Mandatory=$true)][string] $newIp) | |
$zones = Get-DnsServerZone | |
$zoneNames = $zones | Select-Object -Property ZoneName | |
ForEach ($zoneName in $zoneNames) { | |
$records = Get-DnsServerResourceRecord $zoneName.ZoneName -RRType "A" | |
ForEach ($record in $records) { | |
If ($record.RecordData.IPv4Address -eq $oldIp) { | |
$clone = $record.Clone() | |
$clone.RecordData.IPv4Address = $newIp | |
Set-DnsServerResourceRecord -NewInputObject $clone -OldInputObject $record -ZoneName $zoneName.ZoneName | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment