Public/Copy-DNSZoneReverse.ps1
Function Copy-DNSZoneReverse { param( [Parameter(Mandatory)][string]$SrcServer, [Parameter(Mandatory)][string]$DestServer ) $Zones = Get-DnsServerZone -ComputerName $SrcServer | Where-Object { $_.ZoneType -eq 'Primary' -and $_.IsAutoCreated -eq $false -and $_.IsReverseLookupZone -eq $true } | Select-Object -ExpandProperty ZoneName | Select-Object @{name = 'SrcZone'; expression = { $_ } }, @{name = 'DestZone'; expression = { $_.Split('.')[-3..-1] -Join '.' } } | Sort-Object DestZone, SrcZone ForEach ($Zone in $Zones) { # If consolidating zones all on one server (src and dest), then do not copy the top-level reverse zones back into themselves. If (($SrcServer -eq $DestServer) -and ($Zone.srcZone.Split('.').Count -eq 3)) { "`n`n- - - - - - - - - - -`n$Zone" Write-Warning "Skipping zone to avoid duplication when Source and Destination servers are same." } Else { "`n`n- - - - - - - - - - -`n$Zone" Copy-DNSServerZone -SrcServer $SrcServer -SrcZone $Zone.SrcZone -DestServer $DestServer -DestZone $Zone.DestZone -StaleDays 21 | Out-Host } } } |