Clear Exchange Server 2016 Logs

In this blog post, I’ll show you how to clear Exchange Server 2016 and 2013 logs and free a lot of disk space from Exchange Server.

Exchange Server 2016  Logs

Not a lot of Admins know It until it’s too late and Exchange Server Is about to run out of space, but Exchange Server 2016 and 2013 log almost everything Into the disk.

This new feature Is great but If you are not aware If you will be surprised when your new Exchange Server Is out of space and email Is not working.

As you can see below, My Exchange Server 2016 Logging directory has 36GB of logs which were filled In less than a week.

In the Logging\AutoDiscover directory all the logs are kept and unless deleted they will keep going.

The Solution

Luckily, Microsoft released a great script that clears all the logs without breaking Exchange Server.

In my case, all I had to do Is change the path of the logs from C to D, If didn’t changed the default Exchange Install there Is nothing to change.

I created a task Schedule and used it to run every day.

Note: This script will not delete database log files.

Set-Executionpolicy RemoteSigned



$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"

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 -Include *.log,*.blg, *.etl -Recurse | Where {$_.LastWriteTime -le "$LastWrite"}

$Files = Get-ChildItem "C:\Program Files\Microsoft\Exchange Server\V15\Logging\" -Recurse | Where-Object {$_.Name -like "*.log" -or $_.Name -like "*.blg" -or $_.Name -like "*.etl"} | where {$_.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"







Before running the script

As you can see, before running the script I had 62GB free

Below you can see the script In action

After the script run, I have 96 GB free





2 responses to “Clear Exchange Server 2016 Logs”

  1. Thomas Avatar


    the cleanup dont works any more. Only the C:\program Files\exchange 15 Folder will be cleaned up. whats the problem?


  2. Doug Yoder Avatar
    Doug Yoder

    Awesome sauce! Thanks! Cleared 66GB!