Difference between revisions of "Windows dns export zones to rfc"
Jump to navigation
Jump to search
(Created page with "``` $ErrorActionPreference = "Stop" $dnshost = "txv-dc02" New-Item -ItemType Directory -Force -Path ${PWD}/exports $Session = New-PSSession -ComputerName "$dnshost" Functio...") |
|||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
``` | ``` | ||
| + | if ($dnshost -eq $null) { | ||
| + | $dnshost = read-host -Prompt "Please enter windows dns host to exports zones" | ||
| + | } | ||
$ErrorActionPreference = "Stop" | $ErrorActionPreference = "Stop" | ||
| − | |||
New-Item -ItemType Directory -Force -Path ${PWD}/exports | New-Item -ItemType Directory -Force -Path ${PWD}/exports | ||
$Session = New-PSSession -ComputerName "$dnshost" | $Session = New-PSSession -ComputerName "$dnshost" | ||
| Line 9: | Line 11: | ||
Function exportZones(){ | Function exportZones(){ | ||
$primaryDnsZones = @() | $primaryDnsZones = @() | ||
| − | $primaryDnsZones=(Get-DnsServerZone | Where-Object {($_.ZoneType -eq "Primary" -and $_.ZoneName -ne "TrustAnchors")}).ZoneName | + | $primaryDnsZones=(Get-DnsServerZone | Where-Object {($_.ZoneType -eq "Primary" -and $_.ZoneType.IsAutoCreated -eq "False" -and $_.ZoneName -ne "TrustAnchors")}).ZoneName |
foreach ($zone in $primaryDnsZones){ | foreach ($zone in $primaryDnsZones){ | ||
echo "Exporting zone: $zone" | echo "Exporting zone: $zone" | ||
Latest revision as of 16:14, 10 February 2023
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