Site icon RDR-IT

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.

'# source : https://docs.microsoft.com/en-us/iis/manage/provisioning-and-managing-iis/managing-iis-log-file-storage#delete-old-log-files-by-script
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
        Next
Next
IIS log rotate
Exit mobile version