DNS log rotation on Active Directory

Following on from my DNS logging, here is a bit of PowerShell to help you get log rotation working properly on Active Directory – Put this PS1 script into the task scheduler on the AD DNS servers to run every hour:-

$current_log = Get-ChildItem C:\DNS_Logs\queries*.log | Select-Object
Copy-Item $current_log C:\DNS_Logs\archive\
$now = [double]::Parse((Get-Date -Uformat %Y%m%d%H%M%S))
Set-DnsServerDiagnostics -computername localhost -EnableLoggingToFile $False
Set-DnsServerDiagnostics -computername localhost -EnableLoggingToFile $True -LogFilePath C:\DNS_Logs\queries-$now.log

Note: this assumes logs are kept in C:\DNS_Logs and that C:\DNS_Logs\archive exists as directories


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s