Windows dns export zones to rfc

From UVOO Tech Wiki
Revision as of 15:59, 10 February 2023 by Busk (talk | contribs)
Jump to navigation Jump to search
$ErrorActionPreference = "Stop"

$dnshost = "mydnshostname"
New-Item -ItemType Directory -Force -Path ${PWD}/exports
$Session = New-PSSession -ComputerName "$dnshost"


Function exportZones(){
  $primaryDnsZones = @()
  $primaryDnsZones=(Get-DnsServerZone | Where-Object {($_.ZoneType -eq "Primary" -and $_.ZoneName -ne "TrustAnchors")}).ZoneName
  foreach ($zone in $primaryDnsZones){
    echo "Exporting zone: $zone"
    $file="C:\Windows\System32\dns\$zone"
    rm $file
    Export-DnsServerZone -Name "$zone" -FileName "$zone"
  }
}


Invoke-Command -ComputerName $dnshost `
-ScriptBlock ${Function:exportZones}

Copy-Item -Force "C:\Windows\System32\dns\*" -Exclude *.log,backup,samples,cache.dns -Destination "${PWD}\exports\" -FromSession $Session