Cleanup IIS Log files on SharePoint

A common problem I see in many of our customers environments is that their SharePoint servers will start to run lower on disk space on the C: drive after being up and running for a while. Asides from the typical growth due to patching the customers have reported that there have been no other changes or software installations done on the servers. If you have built the system partition based on Microsoft’s recommendations of a minimum of 80GB then you wont be getting low for some time, however even seeing a disk starting to drop 5-10GB faster then you expect can cause some alarm.

What I find to be the case more times then not is that they have either not moved the SharePoint logs from the C: partition or they have not setup any type of job to purge the IIS logs. These logs can grow faster then you might think and when you have multiple web applications this just speeds things up further.

There is a quick way to fix this using a few lines of PowerShell code. This method I am outlining does not do any type of archival of the logs. If this is needed some additional code can be added to this to achieve without a tremendous amount of effort. The goal of this is a quick way to purge the logs and regain space. This is particularly useful in dev and QA environments where no historical data is required.

Take the code below and paste it into a text file and save with a .ps1 extension. This script will go through all sub folders below the LogFiles directory and clean up the log files.

get-childitem -Path C:inetpublogsLogFiles -recurse | where-object {$_.lastwritetime -lt (get-date).addDays(-7)} | Foreach-Object { del $_.FullName }

Once saved you can then create a new scheduled task that will call this script on the desired interval to purge your IIS logs and reclaim storage. To change the time the log files are kept you just need to change the number value in the script to the desired number of days.

Another simple solution is to disable the IIS logging, to do this, you have to do the following:

  1. Open IIS Manager and navigate to the level you want to manage. For information about opening IIS Manager.
  2. In Features View, double-click Logging.
  3. On the Logging page, in the Actions pane, click Enable to enable logging or click Disable to disable logging.

That’s all, hope it helps!!


One thought on “Cleanup IIS Log files on SharePoint

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 )

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