Delete text-based Exchange log files, including those from IIS

I start with a warning – don’t ever manually remove Exchange Server database log files. Just don’t do it.

Exchange Server generates log files. Lots of log files. SOME of those aren’t useful and we just want to delete them. Others of those are important and should just be left alone! In general, Exchange Server log files break down into two different types: database log files and everything else.

It is unfortunate, but all Exchange Server log files have the same file extension: “.log”. Therefore, it isn’t possible to make decisions about log files based on the file extension. Only the directory/folder in which a file is located can be used for decision making purposes. This also applies to IIS (Internet Information Services) log files – they all end with “.log”.

On Exchange Server 2013 and Exchange Server 2016, there are three important directories:

‘C:\Program Files\Microsoft\Exchange Server\V15\TransportRoles\Logs’
‘C:\Program Files\Microsoft\Exchange Server\V15\Logging’
‘C:\inetpub\logs\LogFiles’

The first folder contains log files for “Client Access Services” (CAS). Even in Exchange Server 2016, the CAS log files are still maintained separately.

The second folder contains log files for “all other Exchange roles (but not CAS)”.

The third folder contains log files generated by IIS.

For all three folders, the locations shown are the default locations. Discovering non-default locations takes a lot of lines of PowerShell!

Generally speaking, Exchange Server will purge its own log file folders (the first two in the list above), after they reach a certain age (for example, 30 days) or a certain size (for example, 1.5 GiB).

However, IIS never automatically purges its log file folders. Never. Ever.

Especially in the case of IIS, log files can expand to fill all of the C: volume. In the Exchange Server case, Exchange usually reaches a “steady state” – a point at which log file removal balances out log file creation. However, when adding lots of new users or in the case of a new mobile OS version (this has been seen several times with iOS), a significant spike can be experienced in Exchange Server log files (especially the CAS log files).

This script will remove log files from the three named folders. By default, the log files must be at least 3 days old.

Other scripts may allow you to compress and store these log files. That’s great. And in certain situations, log files can provide a lot of information.

But for 99% of my clients – they just want to free up disk space – which this script allows.

The script is available here.

If you have questions or problems, send those to the author, michael at TheEssentialExchange dot com.


Follow me on twitter: @EssentialExch

Leave a Reply

Your email address will not be published. Required fields are marked *