Exchange ServerHow-to

Exchange Server running out of disk space: cleaning IIS, ETL and diagnostic logs safely

Free space on Exchange Server SE and 2019 safely: which IIS, diagnostic and search ETL logs you can delete, which files you must never touch, and how to schedule the cleanup.

When the system drive of an Exchange server fills up, transport applies back pressure and stops accepting mail, and services can start failing. Usually the space hasn't gone to mailboxes but to the diagnostic logging that Exchange and IIS write around the clock. In this post I'll show where that space goes, what you can delete safely, what you must never touch, and how to automate the cleanup so it doesn't come back.

How this guide is organised: How it works → Prerequisites → Step-by-step cleanup → Verify → Tips & gotchasFlow diagram of the article's sections in reading order: 1. How it works. 2. Prerequisites. 3. Step-by-step cleanup (5 steps: Measure before you delete; Decide where IIS logs should live; Remove old IIS, diagnostic and search logs; Let Exchange manage the transport logs; Schedule it). 4. Verify. 5. Tips & gotchas. Toolbox: *.log, Set-FrontendTransportService, Set-MailboxTransportService, Test-ServiceHealth, server › Logging.1How it works2Prerequisites3Step-by-stepcleanup4Verify5Tips & gotchas1Measure before youdelete2Decide where IISlogs should live3Remove old IIS,diagnostic and se…4Let Exchangemanage the trans…5Schedule itTOOLBOX*.logSet-FrontendTransportServiceSet-MailboxTransportServiceTest-ServiceHealthserver › LoggingHow this guide is organised: How it works → Prerequisites → Step-by-step cleanup → Verify → Tips & gotchasFlow diagram of the article's sections in reading order: 1. How it works. 2. Prerequisites. 3. Step-by-step cleanup (5 steps: Measure before you delete; Decide where IIS logs should live; Remove old IIS, diagnostic and search logs; Let Exchange manage the transport logs; Schedule it). 4. Verify. 5. Tips & gotchas. Toolbox: *.log, Set-FrontendTransportService, Set-MailboxTransportService, Test-ServiceHealth, server › Logging.1How it works2Prerequisites3Step-by-step cleanup1Measure before you delete2Decide where IIS logs should live3Remove old IIS, diagnostic and search logs4Let Exchange manage the transport logs5Schedule it4Verify5Tips & gotchasTOOLBOX*.logSet-FrontendTransportServiceSet-MailboxTransportServiceTest-ServiceHealthserver › Logging
At a glance: how this guide is organised · 5 steps · 5 key settings and tools

How it works: where the space goes#

On a default installation everything below sits on the system drive, under %ExchangeInstallPath% (normally C:\Program Files\Microsoft\Exchange Server\V15\) and C:\inetpub:

LocationWhat it holdsWho trims it
C:\inetpub\logs\LogFiles\W3SVC1 and W3SVC2IIS request logs for the Default Web Site (client-facing) and the Exchange Back End siteNobody: IIS rolls over to a new file but never deletes old ones
%ExchangeInstallPath%LoggingProtocol and diagnostic logs (HttpProxy, MapiHttp, RpcHttp, EWS, Managed Availability and more) and the daily performance logs (.blg) under Logging\DiagnosticsPer-component limits only; nothing caps the folder as a whole
%ExchangeInstallPath%Bin\Search\Ceres\Diagnostics\ETLTraces and \LogsTrace (.etl) and text logs from the search componentsEasy to overlook, and a frequent surprise on the system drive
%ExchangeInstallPath%TransportRoles\LogsMessage tracking, connectivity and SMTP protocol logsExchange, by age and folder size

Watch out: never delete database files (.edb), their transaction logs, checkpoint (.chk) or reserve (.jrs) files, or the transport queue database (mail.que) and its logs in TransportRoles\data\Queue. Those logs are also .log files, so a script that deletes *.log recursively is safe in the folders above and destructive if pointed at the install root or a database folder. Database logs are only removed by an Exchange-aware backup or circular logging; see transaction logs filling the disk.

Prerequisites#

  • Local administrator rights and an elevated PowerShell window; the Exchange Management Shell is only needed for step 4.
  • Your log-retention requirement. IIS and HttpProxy logs are what incident responders read after a compromise, so agree how many days you keep (or archive elsewhere) before you shorten anything.

Step-by-step cleanup#

1. Measure before you delete#

PowerShell
Get-Volume | Where-Object DriveLetter | Format-Table DriveLetter, @{n='FreeGB';e={[math]::Round($_.SizeRemaining/1GB,1)}}, @{n='SizeGB';e={[math]::Round($_.Size/1GB,1)}}
$ex = $env:ExchangeInstallPath
$folders = "$env:SystemDrive\inetpub\logs\LogFiles",
           (Join-Path $ex 'Logging'),
           (Join-Path $ex 'Bin\Search\Ceres\Diagnostics\ETLTraces'),
           (Join-Path $ex 'Bin\Search\Ceres\Diagnostics\Logs'),
           (Join-Path $ex 'TransportRoles\Logs')
foreach ($f in $folders) {
  $sum = (Get-ChildItem $f -Recurse -File -ErrorAction SilentlyContinue | Measure-Object Length -Sum).Sum
  '{0,8:N1} GB  {1}' -f ($sum / 1GB), $f
}

If Logging is the big one, size its subfolders the same way to see which component is responsible. One folder growing much faster than the rest often points to a component that is failing and logging the same error over and over.

2. Decide where IIS logs should live#

IIS logs are plain text and compress very well, so NTFS compression on the log folder is a cheap win. Better still, move them to a data volume: in IIS Manager › server › Logging, set Directory to a folder such as D:\IISLogs and click Apply. Update the cleanup script path below if you do.

3. Remove old IIS, diagnostic and search logs#

Save this as C:\Scripts\Remove-OldExchangeLogs.ps1. Without -Delete it only reports what it would remove:

PowerShell
param([int]$Days = 14, [switch]$Delete)
$ex = $env:ExchangeInstallPath
$targets = "$env:SystemDrive\inetpub\logs\LogFiles",
           (Join-Path $ex 'Logging'),
           (Join-Path $ex 'Bin\Search\Ceres\Diagnostics\ETLTraces'),
           (Join-Path $ex 'Bin\Search\Ceres\Diagnostics\Logs')
$cutoff = (Get-Date).AddDays(-$Days)
foreach ($t in $targets) {
  if (-not (Test-Path $t)) { Write-Warning "Not found: $t"; continue }
  $old = Get-ChildItem $t -Recurse -File -Include *.log, *.blg, *.etl -ErrorAction SilentlyContinue |
         Where-Object LastWriteTime -lt $cutoff
  '{0,7} files {1,8:N2} GB  {2}' -f $old.Count, (($old | Measure-Object Length -Sum).Sum / 1GB), $t
  if ($Delete -and $old) { $old | Remove-Item -Force -ErrorAction SilentlyContinue }
}

Run .\Remove-OldExchangeLogs.ps1 -Days 14, review the totals, then run it again with -Delete. Files that are still open are locked and simply skipped, and Exchange creates new files as it needs them. The transport logs are deliberately not in the list.

4. Let Exchange manage the transport logs#

Message tracking and protocol logs answer "where did that email go?", so set their limits instead of deleting files (details in message tracking with Get-MessageTrackingLog):

PowerShell
Get-TransportService EX01 | Format-List *LogMaxAge, *LogMaxDirectorySize, *LogPath
Set-TransportService EX01 -MessageTrackingLogMaxAge 30.00:00:00 -MessageTrackingLogMaxDirectorySize 2GB
Set-TransportService EX01 -MessageTrackingLogPath "D:\TransportLogs\MessageTracking"

The connectivity and send/receive protocol logs have matching MaxAge, MaxDirectorySize and Path parameters, and Set-FrontendTransportService and Set-MailboxTransportService have equivalents for the logs of those services. Moving these logs off the system drive is the long-term fix.

5. Schedule it#

PowerShell
$action  = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '-NoProfile -ExecutionPolicy Bypass -File C:\Scripts\Remove-OldExchangeLogs.ps1 -Days 14 -Delete'
$trigger = New-ScheduledTaskTrigger -Daily -At 2am
$princ   = New-ScheduledTaskPrincipal -UserId 'SYSTEM' -LogonType ServiceAccount -RunLevel Highest
Register-ScheduledTask -TaskName 'Exchange log cleanup' -Action $action -Trigger $trigger -Principal $princ

Verify#

  • Re-run the measurement from step 1: the cleaned folders now hold roughly your retention period's worth of files, and free space on the system drive has gone up.
  • After the first scheduled run, Get-ScheduledTaskInfo -TaskName 'Exchange log cleanup' shows a recent LastRunTime and a LastTaskResult of 0.
  • Test-ServiceHealth reports RequiredServicesRunning : True for every role, and new files keep appearing in the cleaned folders, which proves logging still works.
  • If the full disk had triggered back pressure, confirm that queues drain and mail flows again (see 452 4.3.1 back pressure).

Tips & gotchas#

  • Don't switch logging off to save space. You lose the evidence you need for troubleshooting and security investigations; shorten retention or move the logs instead.
  • Keep the target list explicit. Never widen the script to %ExchangeInstallPath% as a whole, the Mailbox folder or TransportRoles\data.
  • Look for one-off space users too: extracted cumulative update files, old ISO images and memory dumps left behind after troubleshooting.
  • If space disappears again quickly, find the folder that grew and the component behind it rather than shortening retention further.
  • Size the system drive with headroom and keep databases, transaction logs and, ideally, the queue database on their own volumes.

References#

Written and checked against current Microsoft Learn documentation. Test changes with a pilot group before rolling them out to everyone, and if an admin center path has moved since, search for the setting name instead.

Spotted a mistake, or did this fix work differently for you? Email me or message me on LinkedIn — corrections are credited in the article.

Written by

Omer Eltayeb

Intune Subject Matter Expert in Cairo, Egypt, former Microsoft Cloud Solutions Architect, Microsoft Certified Trainer and Microsoft Innovative Educator Expert (2024–26) and Microsoft Elevate Educator Expert (2026–27). I share practical, step-by-step guides, study plans, scripts and toolkits for Microsoft Intune, Configuration Manager, Microsoft Entra ID, Microsoft Defender, Exchange and Microsoft 365 with the community.

Microsoft Certified Trainer (MCT) 2026Microsoft Innovative Educator Expert 2025–2026Microsoft Elevate Educator Expert 2026–2027ISC2 Certified Information Systems Security Professional (CISSP)Microsoft 365 Certified: Enterprise Administrator Expert (MS-102)