Jump to content
Dayrak

How to Cleanup IIS Log Files

Recommended Posts

Try this:
 

$Path = "C:\inetpub\logs\LogFiles"
$Daysback = "-120"

$CurrentDate = Get-Date
$DatetoDelete = $CurrentDate.AddDays($Daysback)
Get-ChildItem $Path -Recurse | Where-Object { $_.LastWriteTime -lt $DatetoDelete } | Remove-Item

You can adjust the file path to the log files and the amount of days in the top two sections.

 

If you want to add it to an Automate script to schedule, then use:
Function: Execute Script
Script Type: PowerShell
Script to Exexute: <paste above script with adjustments if needed>
Script Parameters: <leave blank>
Script Credentials: Run as Local Agent
Variable: powershellresults
 

The the current script the variable is pretty arbitrary because it's just going to return 'OK', but you're welcome to make the script a little more verbose to return better results.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×