Delete IIS logs after certain number of days via PowerShell

By |2017-12-04T10:47:06+00:00February 17th, 2011|Azure, PowerShell|0 Comments

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:inetpublogsLogFilesw3svc1” directory. You can alter the script to how many days old the log files can be and also your IIS log location (Highlighted in red).

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

Leave A Comment

like what you see? 

Sign-up to our newsletter and never miss out on the latest blogs, events and tech news from the world of risual
Give it a try, you can unsubscribe anytime.