In this blog, we explore the critical importance of maintaining regular backups for DNS zones on Domain Controllers to ensure the resilience and continuity of your network infrastructure. This simple to use powershell script can help you in implementing a robust backup strategy for your DNS zones, without leveraging any third-party tools.

$old=30
$DNSSERVER="DNSServerName"
$BkfFolder=”c:\windows\system32\dns\backup\Zones”
$List = Get-WmiObject -ComputerName $DNSSERVER -Namespace root\MicrosoftDNS -Class MicrosoftDNS_Zone | Where-Object{$_.reverse -like 'False'} | select name,ZoneType,AllowUpdate,MasterServers,DsIntegrated
$Dailybackups = "\DNSServerName\c$\windows\system32\dns\backup\Zones"
$Finallocation = "\BackupSharePath\Backups\IS-Domain\DNSBackups\DNSServerName"
Get-ChildItem "\BackupSharePath\Backups\IS-Domain\DNSBackups\DNSServerName" | ?{$_.CreationTime -le $old} |Remove-Item -Force
if (Test-Path $Dailybackups)
{
Remove-Item $Dailybackups -recurse
}
New-Item $Dailybackups -type Directory | Out-Null
$list | foreach {
$path=”backup\Zones\”+$_.name+"_"+(get-date -format MMddyyyy)+".txt"
$Archive="\DNSServerName\c$\windows\system32\dns\backup\Zones\"+(get-date -format MMddyyyy)+".zip"
$cmd=”dnscmd {0} /ZoneExport {1} {2}” -f $DNSSERVER,$</em>.Name,$path
Invoke-Expression $cmd
}
Compress-Archive $Dailybackups $Archive
Start-Sleep -Seconds 2
Move-Item $Archive $finallocation