By default Exchange 2013/2106 logs A LOT of data in the “…\Exchange Server\V15\Logging” folder. In larger environments, GBs of data can be logged under the MANY subfolders under this folder. IIS also logs data and has since the IIS 1.0, but nowhere near as much.
A recent post on the Exchange 2013 Information Sharing Facebook group brought up this issue and a blog post on a PowerShell to script to address it. So if you want to do this via PowerShell see that post.
But the method I use is a one-liner Scheduled Task using FORFILES CLI.
Here’s the one-liner: FORFILES /p “C:\Program Files\Microsoft\Exchange Server\V15\Logging” /s /m *.* /c “cmd /c Del @path” /d -7
But you will probably want to run this daily, so follow the steps below on EACH Exchange server to remove older logs on a regular basis.
- Create a scheduled task with the following settings
- General: Runs as administrator, or an account that has delete access to the files
- General: Select “Run whether user is logged on or not”
- Trigger: Daily or how often you want it to remove older files
- Action: Start a program
- Program/script: FORFILES
- No path needed, this EXE was included 1st in Windows Vista and is included in Windows Server 2008 and higher
- Arguments: /p “C:\Program Files\Microsoft\Exchange Server\V15\Logging” /s /m *.* /d -7 /c “cmd /c del @path”
- If you don’t have Exchange 2013/2016 installed in the default path, change the path above to where your E15 Logging folder is
- Change the “-7” to control how many days to keep, “-7” = 7 days
TIP: Repeat these same steps, but for IIS logs and use this argument for step 7: /p “C:\inetpub\logs\LogFiles” /s /m *.* /d -7 /c “cmd /c del @path”
If you also want to delete IIS logs, create a 2nd Task to delete IIS logs, by default they are saved in “C:\inetpub\logs\LogFiles”