Is your Exchange Server 2013 install path disk getting full? It’s most likely due to the hundreds (if not thousands) of diagnostic and monitoring log files (and GBs of data) Exchange can create within every 24-hour period. The default path to these .log files is “C:\Program Files\Microsoft\Exchange Server\V15\Logging”. But don’t try to manually delete them because it will take more time (and energy) than you will want spend.
Use the references at the bottom of this article to provide guidance before proceeding.
Run this script file to target multiple Exchange servers:
- Remove-ExchangeLogFiles (Rename file extension from .doc to .ps1; Author Brian Reid)
Or this command on individual Exchange servers:
Get-ChildItem 'C:\Program Files\Microsoft\Exchange Server\V15\Logging','C:\Inetpub\Logs' -Directory | Get-ChildItem -Include '*.log','*.blg' -Recurse | ? LastWriteTime -lt (Get-Date).AddDays(-30) | Remove-Item
If you use the command above, it might be best to create a scheduled task. For Exchange 2013, open Task Scheduler and select Create Task. Make sure the task runs whether you are logged on or not and set a schedule. In the Actions tab, click new. The Action will be “Start a program”.
For the Settings, enter the following in the “Program/script:” field…
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Then, enter the following in the “Add arguments (optional):” field…
-NonInteractive -WindowStyle Hidden -command ". 'C:\Program Files\Microsoft\Exchange Server\V15\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; Get-ChildItem 'C:\Program Files\Microsoft\Exchange Server\V15\Logging','C:\Inetpub\Logs' -Directory | Get-ChildItem -Include '*.log','*.blg' -Recurse | ? LastWriteTime -lt (Get-Date).AddDays(-30) | Remove-Item
Finally, adjust the retention days to your needs, click OK, enter credentials as required and test running the task.
Have fun!
Reference(s):
- Removing Old Exchange 2013 Log Files (by Brian Reid)
- Exchange 2013 diagnostic and performance log files (by Tony Redmond)
- Exchange 2013 & system logs => Disk getting full
- Exchange 2013 Diagnostic Logging
- Move Logging in Exchange 2013 via PowerShell
- Get-EventLogLevel
- Set-EventLogLevel
- Scheduling an Exchange PowerShell Task
- PowerShell Script: IIS Log File Cleanup and Archive