How to remove Exchange log files?
These files really eat up my storage.
Be sure you backup all files.
Make a file called cleanmx.ps1 (or whatever)
and run it:
.\cleanmx.ps1
The file contains this:
# Set execution policy if not set
$ExecutionPolicy = Get-ExecutionPolicy
if ($ExecutionPolicy -ne "RemoteSigned") {
Set-ExecutionPolicy RemoteSigned -Force
}
Cleanup logs older than the set of days in numbers
$days = 1
Path of the logs that you like to cleanup
$IISLogPath = "C:\inetpub\logs\LogFiles"
$ExchangeLoggingPath = "C:\Program Files\Microsoft\Exchange Server\V15\Logging"
$ETLLoggingPath = "C:\Program Files\Microsoft\Exchange Server\V15\Bin\Search\Ceres\Diagnostics\ETLTraces"
$ETLLoggingPath2 = "C:\Program Files\Microsoft\Exchange Server\V15\Bin\Search\Ceres\Diagnostics\Logs"
Clean the logs
Function CleanLogfiles($TargetFolder) {
Write-Host -Debug -ForegroundColor Yellow -BackgroundColor Cyan $TargetFolder
if (Test-Path $TargetFolder) {
$Now = Get-Date
$LastWrite = $Now.AddDays(-$days)
$Files = Get-ChildItem $TargetFolder -Recurse | Where-Object { $_.Name -like "*.log" -or $_.Name -like "*.blg" -or $_.Name -like "*.etl" } | Where-Object { $_.lastWriteTime -le "$lastwrite" } | Select-Object FullName
foreach ($File in $Files) {
$FullFileName = $File.FullName
Write-Host "Deleting file $FullFileName" -ForegroundColor "yellow";
Remove-Item $FullFileName -ErrorAction SilentlyContinue | out-null
}
}
Else {
Write-Host "The folder $TargetFolder doesn't exist! Check the folder path!" -ForegroundColor "red"
}
}
CleanLogfiles($IISLogPath)
CleanLogfiles($ExchangeLoggingPath)
CleanLogfiles($ETLLoggingPath)
CleanLogfiles($ETLLoggingPath2)
Log files are essential for database consistency and should never be deleted manually. Instead. A proper Exchange-aware backup automatically truncates transaction logs. Verify your backup software supports this. You can do it with Windows backup. You can use Script that can clean up all the things, For detailed instructions and best practices, see article 1 article 2.
I assume your are talking about database transaction log files.
They should never be deleted manually. You should perform a database backup, and that will take care of deleting old log files.
If you are not performing regular database backups (which you really should), there is another option: enable circular logging on the database(s); this will only use several log files to ensure database consistency, and will overwrite them after their transactions are committed.