Skip to content

Instantly share code, notes, and snippets.

@BrendanThompson
Created December 18, 2014 07:03
Show Gist options
  • Save BrendanThompson/9adf34cc015b667cf134 to your computer and use it in GitHub Desktop.
Save BrendanThompson/9adf34cc015b667cf134 to your computer and use it in GitHub Desktop.
Take an input file, and bulk update internal DNS records.
[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