Set Windows Event Log Max Size on Domain Controllers
Recently, we received a request to set the maximum log size of all domain controllers to 25MB. Considering the significant number of domain controllers involved, I turned to PowerShell to streamline the process.
With its efficiency and reliability, PowerShell once again proved to be a trusty ally in completing this task. I quickly knocked up this handy script that retrieves all domain controllers in the forest and then updates the Directory Service, DNS Server, Application, and System logs to match the requested log size of 25MB.
Here’s the code:
$allDCs = (Get-ADForest).Domains | %{ Get-ADDomainController -Filter * -Server $_ }
foreach ($dc in $allDCs){
Write-Host $dc.Name -NoNewline
Invoke-Command -ComputerName $dc.Name -ScriptBlock {
Limit-EventLog -LogName 'Directory Service' -MaximumSize 25MB
Limit-EventLog -LogName 'DNS Server' -MaximumSize 25MB
Limit-EventLog -LogName Application -MaximumSize 25MB
Limit-EventLog -LogName System -MaximumSize 25MB
}
Write-Host " - " -NoNewline
Write-Host "Done!" -ForegroundColor Green
}