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

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.

  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 *.* /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:

About Jason Sherry

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

6 Responses to Remove older Exchange 2013/2016 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.


  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,


  4. Jeroen says:

    Thx Jason. This really helped me.


  5. Tim Ackermann says:

    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.
    Thanks for the info!


Leave a Reply

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

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

Facebook photo

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

Connecting to %s