Removing old log files
Here is a simple script to remove old log files from Exchange Servers at the %ExchangeInstallPath%logging
folder. Here, I have used the default installation path of Exchange, but it can be modified to use a variable with a non-default path of the Exchange installation. The number of days can be modified to suit your needs:
$Days = 30 $ExchangeLogsPath="C:\Program Files\Microsoft\Exchange Server\V15\Logging\" Write-Host "Removing IIS and Exchange logs from Default Directories except last $Days days" $Now = Get-Date $LastModified = $Now.AddDays(-$Days) $LogFiles = Get-ChildItem $ExchangeLogsPath -Include *.log -Recurse | Where {$_.LastWriteTime -le "$LastModified"} foreach ($File in $LogFiles) {Write-Host "Deleting file $File" -ForegroundColor Red; Remove-Item $File -ErrorAction SilentlyContinue | out-null}