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”
Here’s what the scheduled task looks like in Windows 2012 R2:
Pingback: Weekly IT Newsletter – December 8-12, 2014 | Just a Lync Guy
Thanks so much, I followed a post you made, God knows where, while I was researching how to save some space on my C: drive on my Exchange Server. Im a Google IT guy, (meaning no formal training, I google everything and hope it doesn’t explode when I implement) and this really hepled me out and will take care of the issue every day!! Great Blog by the way.
LikeLike
Excellent post, Jason – we’re still in our migration phase and logs are filling up like crazy!
Would you mind if I cross-post to my blog, exchangeitup.blogspot.com?
LikeLike
Welcome to share the info!
LikeLike
Thx Jason. This really helped me.
LikeLike
I had issues running your commands. Here are my updates on Server 2012 R2:
-p “C:\Program Files\Microsoft\Exchange Server\V15\Logging” -s -m *.log -d -30 -c “cmd /C DEL @File”
-p “C:\inetpub\logs\LogFiles” -s -m *.log -d -30 -c “cmd /C DEL @File”
Run with highest privileges
Configure for Windows Server 2012 R2
Found a similar article here that helped me fix it.
https://www.ryadel.com/en/manage-iis-log-files-purge-older-n-days-bat-file/
Thanks for the info!
LikeLike