Remove older Exchange 2013 and IIS Log Files with this one-liner


By default Exchange 2013 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.

  1. Create a scheduled task with the following settings
  2. General: Runs as administrator, or an account that has delete access to the files
  3. General: Select “Run whether user is logged on or not”
  4. Trigger: Daily or how often you want it to remove older files
  5. Action: Start a program
  6. Program/script: FORFILES
    • No path needed, this EXE was included 1st in Windows Vista and is included in Windows Server 2008 and higher 
  7. Arguments: /p “C:\Program Files\Microsoft\Exchange Server\V15\Logging” /s /m *.* /c “cmd /c Del @path” /d -7
  • If you don’t have Exchange 2013 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

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:
Tasks

About jasonsherry

I am a 20 year Exchange consultant and expert. I currently work for Commvault as a Solutions Specialist for Microsoft Infrastructure For more info see my resume at: http://jasonsherry.org
This entry was posted in Exchange, Technical and tagged . Bookmark the permalink.

5 Responses to Remove older Exchange 2013 and IIS Log Files with this one-liner

  1. Pingback: Weekly IT Newsletter – December 8-12, 2014 | Just a Lync Guy

  2. senatormc says:

    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.

    Like

  3. 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?

    Like

  4. Jeroen says:

    Thx Jason. This really helped me.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s