Skip to main content

Purge IIS Logs Older than X Days Param

Summary

This script will remove IIS log files older than (Global Variable, Days) days only if the size of the c:/inetpub/logs/logfiles/w3svc folder is greater than (Global Variable Size) MB.
The recommended schedule for this script is:
Target: "Labtech Server" Group
Occurrence: Run once per week

By default, it will remove the logs older than 30 days if the size of the directory is greater than 1024 MB.

Also, the script can be used for on-prem partners only.

Sample Run

Sample Run Image

Preferred is to schedule the script against the "Labtech Server" to run once per week:
Schedule Image

Variables

NameDescription
psoutOutcome of the PowerShell running to purge the IIS logs

Global Parameters

NameExampleRequiredDescription
days30TrueDays to keep the logs. Default is 30
Size1024TrueThreshold in MB to initiate the purging. The script will only remove the IIS logs older if the size of the logs directory goes above this size. Default is 1024
pathc:/inetpub/logs/logfiles/w3svc*/*.logTruePath to the IIS logs

Process

Step 1: Executes a PowerShell script to verify the size of the logs directory and to clear the logs older than @days@ days, if it finds the size above @size@ MB.
Step 2: Generates the logs as per the PowerShell script's outcome and exits.

Output

  • Script Log