Delete old exchange 2013 iis logs

Exchange 2013 generates by default a huge amount of logs, especially in the form of IIS logs, The really brilliant thing is that there is no process that cycles or clean up them and, if you leave them in the default path, you risk to fill up a C disk even of 100 giga in a few months (obviously it depends on the size of your infrastructure).

These logs are located in the default path:



However if you want to limit the size of these logs, you can use this powershell scripts and schedule it by task scheduler:

$limit = (Get-Date).AddDays(-60)
$path1 = “C:inetpublogsLogFilesW3SVC1”
$path2 = “C:inetpublogsLogFilesW3SVC2”

# Delete logs older than the $limit.
Get-ChildItem -Path $path1 -Recurse -Force | Where-Object { !$_.PSIsContainer -and $_.CreationTime -lt $limit } | Remove-Item -Force
Get-ChildItem -Path $path2 -Recurse -Force | Where-Object { !$_.PSIsContainer -and $_.CreationTime -lt $limit } | Remove-Item -Force

What the script does is to simply delete files older than 60 days in the two IIS log directories, if you want to test it, before actually deleting files, you can add a -whatif at the end of the two remove-item commands.

To schedule the script simply create a task passing powershell.exe as the program to run and the .ps1 script to run with all its path as argument (i.e.. c:scriptsdeleteoldexchangelogs.ps1):


Leave a comment

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