Wednesday, March 11, 2015

Clean the exchange server logfiles

At a client I found that disks were filling up with logfiles. Most but not all logfiles were cleared automatically after 7 or 14 days but that left a few logfiles filling up the disk..

I created a scheduled task which runs every night (after the backup run) and removes all old logfiles:

It is a powershell one liner:

powershell.exe Get-ChildItem 'c:\Program Files\Microsoft\Exchange Server\V15\Logging','C:\inetpub\logs' -Directory | Get-ChildItem -Include '*.log','*.blg' -Recurse | ? LastWriteTime -lt (Get-Date).AddDays(-7) | Remove-Item

 This script will remove all logfiles older than 7 days.

No comments:

Post a Comment