Created
December 18, 2014 07:03
-
-
Save BrendanThompson/9adf34cc015b667cf134 to your computer and use it in GitHub Desktop.
Take an input file, and bulk update internal DNS records.
This file contains hidden or 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
[CmdletBinding()] | |
Param ( | |
[string] $inputFile, | |
[switch] $dr, | |
[switch] $prd | |
) | |
Write-Verbose "Global Variable Declaration" | |
New-Variable -Scope Global -Name IP_Type | |
New-Variable -Scope Global -Name ServerList -Value $((Get-Content -Path $inputFile) -Join "`n" | ConvertFrom-Json) | |
if ($dr) | |
{ | |
Set-Variable -Scope Global -Name IP_Type -Value "DR_IP" | |
} | |
elseif ($prd) | |
{ | |
Set-Variable -Scope Global -Name IP_Type -Value "PRD_IP" | |
} | |
else | |
{ | |
Write-Error "No Valid IP Configuration Selected" | |
exit 1 | |
} | |
function updateDnsRecords | |
{ | |
foreach ($server in $ServerList.ServerNames) | |
{ | |
Write-Verbose "Updating Records for $server" | |
$currentServer = $ServerList.Servers."$server" | |
$currentDnsEntry = Get-DnsServerResourceRecord -ZoneName $currentServer.ZoneName -Name "$server" | |
$newDnsEntry = $currentDnsEntry.Clone() | |
$newDnsEntry.RecordData.IPv4Address = $currentServer.$IP_Type | |
Write-Verbose "Current IP Address: $(currentDnsEntry.RecordData.IPv4Address.IPAddressToString) being updated to $($currentServer.$IP_Type)" | |
Set-DnsServerResourceRecord -ZoneName $currentServer.ZoneName -OldInputObject $currentDnsEntry -NewInputObject $newDnsEntry | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment