How to Clear IIS Log Files on Windows Server 2012?

IIS (Internet Information Services) Web Server on Windows Server generates a sufficiently large amount of log files during its work. The main problem is that by default IIS log files located on the system drive, which usually has a small size. Insufficient space on the system drive may eventually cause to server crash. Continuous extension of the system drive (even on a virtual machine) due to the large size of the IIS log files also is not the best solution.

Delete IIS Log Files on Windows Server 2012

In this article we will show you how to handle the IIS log files and automate the process of their deleting on Windows Server 2012.

By default, IIS logs stored in the directory:

  • Windows Server 2003: %windir%\system32\LogFiles
  • Windows Server 2012/2008: %SystemDrive%\inetpub\logs\LogFiles

Administrator can change the path to the logs using the Internet Information Services (IIS) Manager snap-in by specifying the required directory in the Logging section of site settings.


clear iis logs

In our case, on Exchange Server 2013 with almost 1,000, IIS generate about 200 MB file per day. Thus, for the year it accumulated about 70 GB of logs!

In case of exhaustion space on the servers system drive, system administrators are beginning to look for what takes so much space, and safely passed inetpub folder, because, at first glance, it has small size. This is because by default Administrator does not have permissions on the subfolders of inetpub, so File Explorer does not show the real size of folder.

delete iis logs

Try to open each subfolder in the directory %SystemDrive%\inetpub\logs\LogFiles, agreeing with the appointment of the necessary permission and eventually see that the real volume of folders is not so small.

how to clear iis logs

As a rule, you can safely remove all the log files older than 3-7 days. You can do this manually (not the best choice), or automatically using PowerShell script that will be cleaning log files on schedule.

PowerShell script that will remove all files older than 7 days in the directory C:\inetpub\logs with the *.log extension might be look like this:

gci ‘C:\inetpub\logs -Include ‘*.log’ -Recurse | ? LastWriteTime -LT (Get-Date).AddDays(-7) | Remove-Item

To run this script automatically, create a new job using Task Scheduler:

  • Run Task Scheduler
  • In the Action pane select Create Basic Task
  • Specify task Name: CleanUpIISLogs
  • Trigger task to start weekly on Sunday
  • Action: Start a program
  • Program: exe
  • Arguments: -NoProfile -command “gci ‘C:\inetpub\logs’ -Include ‘*.log’ -Recurse | ? LastWriteTime -LT (Get-Date).AddDays(-7) | Remove-Item”
    delete iis log files
  • Open Properties of the created task
    inetpub logs
  • Now change the user under which the task runs to NT AUTHORITY\System and check the option Run with highest privileges
    how to delete iis logs
  • To test the task, right click on it and select Run
    clean iis logs
  • Make sure that the log files older than 7 days is removed

Bonus tip. Enabling NTFS compression for the whole folder is another great way to quickly reduce the size of the directory with IIS log file. Since log files contain simple text records, their size is reduced significantly when compressed (approximately in 4x times). To enable compression, select Logs folder properties and click on the Advanced button. Check the box Compress contents to save disk space and press OK twice.

iis log files cleanup

I enjoy technology and developing websites. Since 2012 I'm running a few of my own websites, and share useful content on gadgets, PC administration and website promotion.
Latest posts by Cyril Kardashevsky (see all)


  1. You are missing a ‘ at the end of the log location. You either need to add it or remove the one from the beginning.

  2. Please look out for using “curly” apostrophes and quotation marks. Require changes when adding to script or scheduled task using powershell.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.