Archive (Backup and Delete) IIS Logs in SharePoint

IIS logs are the requests from clients and written into text-based log files. It captures every web page/image/script requests. By default, IIS logs stored in C:\ of WFE servers. If SharePoint is being accessed a lot, It may cause disk space problems for your OS drive so quickly. So we can change this log path. Here is how:

  1. Go into IIS Manager for each WFE. (Start > run > Inetmgr)
  2. Select the server name in the Connections panel on the left.
  3. In the Features view shown in the middle panel, select Logging.
  4. For the log file, change the directory to a more suitable drive and folder. For example, I’ve changed the path for the log files to D:\Logs\IIS.
sharepoint 2010 iis logs location

How about backing up them Monthly and deleting old logs?

It’s a good idea to back up and clean IIS Logs every Month. These Logs are highly compressible up to 500%!!! (Meaning 500 MB file to 5 MB file).

1. Download and import the PowerShell community Extension (for write-zip cmd-let)
2. Write the script to Zip and Delete IIS Logs
3. Schedule the script to run on every month ( or based on your schedule)

Step 1: Download and import the PowerShell community Extension
Download the PowerShell community Extension from, and then unblock it (Right-click the downloaded .zip file > go to Properties > click on “Unblock” button)

Fire up PowerShell, Get it to your modules folder, typically it would be “C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules”
cd $PSHome\Modules

Extract the PowerShell community Extension Zip file to a folder, Say: pscx . Now, import the downloaded modules:
import-module Pscx


Step 2: Write the script to Zip and Delete IIS Logs
Now the next step: Writing PowerShell script to Zip and delete the Old log files, Here is the script:

Set-ExecutionPolicy RemoteSigned #important
$date=get-date -UFormat %m-%d-%y
write-zip -Path C:\Logs\IIS -Outputpath C:\Logs\$
move-item c:\Logs\$ D:\IISLogBackup\
get-childitem C:\Logs\IIS -include *.log -recurse | remove-item

Place the above script in to a file, Say: d:\Scripts\IISCleanup.ps1

Step 3: Schedule the script to run on every month
Finally, We need to schedule the script in the Windows Task Scheduler. Go to Start > All Programs > Administrative tools > Task Scheduler, and create the task to run the script at d:\Scripts\IISCleanup.ps1.
powershell.exe D:\scripts\IISLogsClear.ps1 If you get exceptions like “File not found..” then add the paths D:\Scripts, PowerShell’s path in System Environment variable.

Update: Here is my latest post on the same topic: PowerShell Script to compress and delete SharePoint ULS & IIS Logs

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. Passionate about sharing the deep technical knowledge and experience to help others, through the real-world articles!

One thought on “Archive (Backup and Delete) IIS Logs in SharePoint

  • HI i would like to say thanks to you, i am searching this type of article, it’s helped lot…


Leave a Reply

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