Windows dns export zones to rfc
Jump to navigation
Jump to search
if ($dnshost -eq $null) { $dnshost = read-host -Prompt "Please enter windows dns host to exports zones" } $ErrorActionPreference = "Stop" 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 $_.ZoneType.IsAutoCreated -eq "False" -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