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 : 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

 



Related Posts


Windows 10: Install an IIS web server
Presentation In this article, I will explain how to install an IIS web server on a computer with Windows 10. IIS is a Web server developed by Microsoft that is also available on servers. The version installed on the client is called IIS Express, it i

Redirect HTTP to HTTPS over IIS
In this tutorial, we'll see how to automatically redirect http requests to https under IIS. Prerequisites : Valid configuration of your site with SSL. Have the Rewrite module installed under IIS. The Rewrite module is available with Web App Redirect

Printer mapping: GPO and Script
When setting up an Active Directory, one of the things you want to set up automatically is the printer mapping to the different users. Before setting up GPOs, you must have shared your printers. As for mapping network drives, I'll introduce you to tw