Microsoft Exchange creates a lot of logs. Unless these are managed, they can quickly fill up your disk space. The following describes one way to use PowerShell and Task Scheduler to automatically purge the Exchange 2013+ and IIS logs. Scheduled task would be useful for Hybrid deployments where Exchange Server is used just for managing mailbox properties (applies Hybrid Identities) and you are not really too much interested in deeper diagnostic logs.
Scheduled Task Summary
Task Name | Purge Exchange logs older than 7 days |
Function | Deletes all Exchange logs older than 7 days from the following location ‘c:\program files\microsoft\exchange server\V15\Logging’ |
Schedule | Daily at 1am |
Program Called | C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe |
Parameters | -NonInteractive -WindowStyle Hidden -command “. ‘c:\program files\microsoft\exchange server\V15\bin\RemoteExchange.ps1’; Connect-ExchangeServer -auto; gci ‘c:\program files\microsoft\exchange server\V15\Logging’ -Directory | gci -Include ‘*.log’,’*.blg’ -Recurse | ? LastWriteTime -lt (Get-Date).AddDays(-7) | Remove-Item |
Runs As | SYSTEM |
Task Name | Purge IIS logs older than 14 days |
Function | Deletes all IIS logs older than 14 days from the following location ‘c:\inetpub\logs’ |
Schedule | Daily at 1am |
Program Called | C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe |
Parameters | -NonInteractive -WindowStyle Hidden -command “. ‘c:\program files\microsoft\exchange server\V15\bin\RemoteExchange.ps1’; Connect-ExchangeServer -auto; gci ‘C:\inetpub\logs’ -Directory | gci -Include ‘*.log’,’*.blg’ -Recurse | ? LastWriteTime -lt (Get-Date).AddDays(-14) | Remove-Item |
Runs As | SYSTEM |
No comments:
Post a Comment