Delete IIS logs after certain number of days via PowerShell

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

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 }