Knowlege base

Prevent IIS Log files from using too much disk space on Windows Server

Article ID: 892
Last updated: 09 Mar, 2022

Description:

The log files that IIS generates can, over time, consume a large amount of disk space.
Logs can potentially fill up an entire hard drive. 

How-to:

1. Create a new vbs script in a new folder (example C:\Program Files (x86)\StonevoiceAS\Script\IIS Log Retention\iislogretention.vbs)
2. Put this in the script file and change iMaxAge variable to the number of das you'd like to retain logs for.

sLogFolder = "C:\inetpub\logs\LogFiles\W3SVC1"
iMaxAge = 30   'in days
Set objFSO = CreateObject("Scripting.FileSystemObject")
set colFolder = objFSO.GetFolder(sLogFolder)
For Each colSubfolder in colFolder.SubFolders
        Set objFolder = objFSO.GetFolder(colSubfolder.Path)
        Set colFiles = objFolder.Files
        For Each objFile in colFiles
                iFileAge = now-objFile.DateCreated
                if iFileAge > (iMaxAge+1)  then
                        objFSO.deletefile objFile, True
                end if
        Next
Next

An example here

3. Set up a scheduled task to execute that script
Using the Windows Task Scheduler, create a new task and set the trigget to execute daily.
Create new action that looks like the following:

Just put:
- cscript in Program/script field
- the path (example "C:\Program Files (x86)\StonevoiceAS\Script\IIS Log Retention\iislogretention.vbs") to your scipt file inside the arguments textbox.

Article ID: 892
Last updated: 09 Mar, 2022
Revision: 3
Views: 346
Print Export to PDF Subscribe Share
This article was:  
Prev   Next
How to Apply Transparent Data Encryption (TDE) in SQL Server     How to migrate IAS data to a new SQL Server instance