PowerShell – Delete old IIS logs

Just a quick script that may come in useful to you. The below PowerShell script will delete IIS Log files older than 7 days that are in the “C:\inetpub\logs\LogFiles\w3svc1” directory. You can alter the script to how many days old the log files can be and also your IIS log location.

get-childitem -Path C:inetpublogsLogFilesw3svc1 -recurse | where-object {$_.lastwritetime -lt (get-date).addDays(-7)} | Foreach-Object { del $_.FullName }


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.