Press "Enter" to skip to content

Vbs: IIS log rotation script

Unlike linux, Windows does not have a task for log rotation.

Below is a Vbs script that allows you to do this rotation.

By adapting the sLogFolder variable, it is possible to run this script for any location where there are log files.

'# source :
sLogFolder = "c:\inetpub\logs\LogFiles"	'Emplacement des logs
iMaxAge = 30   'Retention en jours
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


Leave a Reply

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