
Using this script you can schedule a backup of forward lookup zones and keep the archive for 30 days.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | $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 |
Leave a Reply