IISLogsCleanup.ps1 is a PowerShell script to compress and archive IIS log files.

This script will check the folder that you specify, and any files older than the first day of the previous month will be compressed into a zip file. If you specify an archive path as well the zip file will bemoved to that location.

The recommended use for this script is a once-monthly scheduled task run on the first day of each month. This will compress all files older than the first day of the previous month, resulting in only 1-2 monthsof log files being stored on the server.

If the script detects any issues with the archive process that may indicate that a file was missed it will not delete the log files from the folder.

The script also writes a log file each time it is run so you can check the results or troubleshoot any issues.

Example usage:

This example will compress the log files in "D:\IIS Logs\W3SVC1" and leavethe zip files in that location.

PowerShell
Edit|Remove
.\IISLogsCleanup.ps1 -Logpath "D:\IIS Logs\W3SVC1"
This example will compress the log files in "D:\IIS Logs\W3SVC1" and move the zip files to the archive path.

PowerShell
Edit|Remove
.\IISLogsCleanup.ps1 -Logpath "D:\IIS Logs\W3SVC1" -ArchivePath "\\nas01\archives\iislogs"
More information about IISLogsCleanup.ps1 is available at Exchange Server Pro. Comments and feedback are welcome there.