Skip to main content

Purge IIS Logs Older than 3 Days

Summary​

This script will remove IIS log files older than 3 days from the path C:/inetpub/logs/LogFiles. The script will provide log files that show which files were not deleted from that folder that are older than 3 days.

The script runs the PowerShell command to perform the task.

Additionally, the path and threshold are defined within the script, rather than in the .ps1 file.

Example Agent Procedure Log​

TimeActionStatusUser
9:59:52 am 12-Jul-23IIS Log Files PurgeSuccess THENovais.rashid
9:59:52 am 12-Jul-23IIS Log Files Purge-0004Success THENovais.rashid
9:59:52 am 12-Jul-23IIS Log Files Purge-0004Path not presentovais.rashid
9:59:52 am 12-Jul-23IIS Log Files Purge-0003Success ELSEovais.rashid
9:59:52 am 12-Jul-23IIS Log Files Purge-0003Script moving to next stepovais.rashid
9:59:52 am 12-Jul-23IIS Log Files Purge-0002Success ELSEovais.rashid
9:59:52 am 12-Jul-23IIS Log Files Purge-0002Script moving to next stepovais.rashid
9:59:52 am 12-Jul-23IIS Log Files Purge-0001Success THENovais.rashid
9:59:52 am 12-Jul-23IIS Log Files Purge-0001Path not presentovais.rashid
9:59:52 am 12-Jul-23IIS Log Files PurgePath 'C:/inetpub/logs/LogFiles' not found.ovais.rashid
9:59:52 am 12-Jul-23Execute Shell command - Get Results to VariableSuccess THENovais.rashid
9:59:52 am 12-Jul-23Execute Shell command - Get Results to Variable-0001Success THENovais.rashid
9:59:51 am 12-Jul-23Execute Shell command - Get Results to Variable-0010Success THENovais.rashid
9:59:50 am 12-Jul-23Execute Shell command - Get Results to Variable-0002Success THENovais.rashid
9:59:50 am 12-Jul-23Execute Shell command - Get Results to Variable-0003Success THENovais.rashid
9:59:50 am 12-Jul-23Execute Shell command - Get Results to Variable-0004Success THENovais.rashid
9:59:50 am 12-Jul-23Execute Shell command - Get Results to Variable-0005Success ELSEovais.rashid
9:59:50 am 12-Jul-23Execute Shell command - Get Results to Variable-0005Executing command in 64-bit shell as system: C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -ExecutionPolicy Bypass -Command "& 'C:/ProgramData/_automation/AgentProcedure/IISPURGE/Remove-OlderFiles.ps1' -Path 'C:/inetpub/logs/LogFiles' -ThresholdDays 3" >"c:/Proval/commandresults-2144853229.txt" 2>&1ovais.rashid
9:59:49 am 12-Jul-23Execute Powershell CommandSuccess THENovais.rashid
9:59:49 am 12-Jul-23Execute Powershell Command-0001Success THENovais.rashid
9:59:49 am 12-Jul-23Execute Powershell Command-0002Success THENovais.rashid
9:59:49 am 12-Jul-23Execute Powershell Command-0011Success THENovais.rashid
9:59:49 am 12-Jul-23Execute Powershell Command-0012Success ELSEovais.rashid
9:59:48 am 12-Jul-23Execute Powershell Command-0011Powershell command completed!ovais.rashid
9:59:46 am 12-Jul-23Execute Powershell Command-0011Executing powershell "" -Command "New-Item -Type Directory -Path C:/ProgramData/_automation/AgentProcedure -Name IISPURGE" ""ovais.rashid
9:59:46 am 12-Jul-23Execute Powershell Command-0009Success THENovais.rashid
9:59:46 am 12-Jul-23Execute Powershell Command-0010Success ELSEovais.rashid
9:59:46 am 12-Jul-23Execute Powershell Command-0010Not sending output to variable.ovais.rashid
9:59:46 am 12-Jul-23Execute Powershell Command-0007Success THENovais.rashid
9:59:46 am 12-Jul-23Execute Powershell Command-0008Success THENovais.rashid
9:59:46 am 12-Jul-23Execute Powershell Command-0008New command variable is: -Command "New-Item -Type Directory -Path C:/ProgramData/_automation/AgentProcedure -Name IISPURGE"ovais.rashid
9:59:46 am 12-Jul-23Execute Powershell Command-0008Custom commands detected as New-Item -Type Directory -Path C:/ProgramData/_automation/AgentProcedure -Name IISPURGEovais.rashid
9:59:46 am 12-Jul-23Execute Powershell Command-0003Success THENovais.rashid
9:59:46 am 12-Jul-23Execute Powershell Command-0004Success ELSEovais.rashid
9:59:43 am 12-Jul-23Execute Powershell Command-0002Powershell is present.ovais.rashid
9:59:35 am 12-Jul-23Run Now - IIS Log Files PurgeAdmin ovais.rashid scheduled procedure Run Now - IIS Log Files Purge to run at Jul 12 2023 9:59 AMovais.rashid
TimeActionStatusUser
9:47:52 am 12-Jul-23IIS Log Files PurgeSuccess THENovais.rashid
9:47:52 am 12-Jul-23IIS Log Files Purge-0004Success ELSEovais.rashid
9:47:52 am 12-Jul-23IIS Log Files Purge-0003Success THENovais.rashid
9:47:52 am 12-Jul-23IIS Log Files Purge-0003Files older than 3 days have been removed.ovais.rashid
9:47:52 am 12-Jul-23IIS Log Files Purge-0002Success ELSEovais.rashid
9:47:52 am 12-Jul-23IIS Log Files Purge-0002Script moving to next stepovais.rashid
9:47:52 am 12-Jul-23IIS Log Files Purge-0001Success ELSEovais.rashid
9:47:52 am 12-Jul-23IIS Log Files PurgeFiles older than 3 days from 'C:/ProgramData/_automation/app/Soji' have been removed.ovais.rashid
9:47:52 am 12-Jul-23Execute Shell command - Get Results to VariableSuccess THENovais.rashid
9:47:52 am 12-Jul-23Execute Shell command - Get Results to Variable-0001Success THENovais.rashid
9:47:51 am 12-Jul-23Execute Shell command - Get Results to Variable-0010Success THENovais.rashid
9:47:50 am 12-Jul-23Execute Shell command - Get Results to Variable-0002Success THENovais.rashid
9:47:50 am 12-Jul-23Execute Shell command - Get Results to Variable-0003Success ELSEovais.rashid
9:47:50 am 12-Jul-23Execute Shell command - Get Results to Variable-0006Success THENovais.rashid
9:47:50 am 12-Jul-23Execute Shell command - Get Results to Variable-0007Success ELSEovais.rashid
9:47:50 am 12-Jul-23Execute Shell command - Get Results to Variable-0007Executing command in standard shell as system: C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -ExecutionPolicy Bypass -Command "& 'C:/ProgramData/_automation/AgentProcedure/IISPURGE/Remove-OlderFiles.ps1' -Path 'C:/ProgramData/_automation/app/Soji' -ThresholdDays 3" >"c:/Proval/commandresults-1103009589.txt" 2>&1ovais.rashid
9:47:48 am 12-Jul-23Execute Powershell CommandSuccess THENovais.rashid
9:47:47 am 12-Jul-23Execute Powershell Command-0001Success THENovais.rashid
9:47:47 am 12-Jul-23Execute Powershell Command-0002Success THENovais.rashid
9:47:47 am 12-Jul-23Execute Powershell Command-0011Success THENovais.rashid
9:47:47 am 12-Jul-23Execute Powershell Command-0012Success ELSEovais.rashid
9:47:47 am 12-Jul-23Execute Powershell Command-0011Powershell command completed!ovais.rashid
9:47:45 am 12-Jul-23Execute Powershell Command-0011Executing powershell "" -Command "New-Item -Type Directory -Path C:/ProgramData/_automation/AgentProcedure -Name IISPURGE" ""ovais.rashid
9:47:45 am 12-Jul-23Execute Powershell Command-0009Success THENovais.rashid
9:47:45 am 12-Jul-23Execute Powershell Command-0010Success ELSEovais.rashid
9:47:45 am 12-Jul-23Execute Powershell Command-0010Not sending output to variable.ovais.rashid
9:47:45 am 12-Jul-23Execute Powershell Command-0007Success THENovais.rashid
9:47:45 am 12-Jul-23Execute Powershell Command-0008Success THENovais.rashid
9:47:45 am 12-Jul-23Execute Powershell Command-0008New command variable is: -Command "New-Item -Type Directory -Path C:/ProgramData/_automation/AgentProcedure -Name IISPURGE"ovais.rashid
9:47:45 am 12-Jul-23Execute Powershell Command-0008Custom commands detected as New-Item -Type Directory -Path C:/ProgramData/_automation/AgentProcedure -Name IISPURGEovais.rashid
9:47:45 am 12-Jul-23Execute Powershell Command-0003Success THENovais.rashid
9:47:45 am 12-Jul-23Execute Powershell Command-0004Success ELSEovais.rashid
9:47:43 am 12-Jul-23Execute Powershell Command-0002Powershell is present.ovais.rashid
9:47:34 am 12-Jul-23Run Now - IIS Log Files PurgeAdmin ovais.rashid scheduled procedure Run Now - IIS Log Files Purge to run at Jul 12 2023 9:47 AMovais.rashid

Dependencies​

None

Output​

Script Logs

Attachments​

Procedure_Purge_IIS_Logs_Older_than_3_Days.xml Remove-OlderFiles.ps1

Changelog​

2025-04-10​

  • Initial version of the document