This will be a short post today with a very useful PowerShell example. With the introduction of Exchange 2013, Microsoft included very detailed and powerful logging. Many of the common components write to “C:\Program Files\Microsoft\Exchange Server\V15\Logging”. This is wonderful for troubleshooting an issue, as you can dive into great depth and find the problem location. However, in an Exchange environment of even our modest size, that produces over 20 gigabytes per day in text logs alone.
Now certainly we could give our Exchange installation drive a large amount of space; however, I am the type of admin who would rather be frugal in assigning storage. Otherwise, I would find that with a few hundred virtual machines that extra space allotted will add up quickly. Also under consideration is the fact that when the install drive gets too low, the message queue will start rejecting messages. This means that the logs should be kept under control to always ensure availability to receive messages.
To do so I use the following command:
gci ‘C:\Program Files\Microsoft\Exchange Server\V15\Logging’,’C:\inetpub\logs’ -Directory |gci -Include ‘*.log’,’*.blg’ -Recurse | ? LastWriteTime -lt (Get-Date).AddDays(-7) | Remove-Item
This allows me to clean up not only the Exchange logs, but also the IIS logs that accumulate as well. I prefer to keep some logging from the transport connectors in case I need to trace an issue. You can also add more folders to clean up or file types that should be included. This shows 7 days but you should determine how much you would like to keep.
The nice thing is that you can save the command to a .ps1 and schedule it via task scheduler in Windows. Then you do not have to worry about install drive space left and keep some of those pesky SCOM drive size alerts at bay.
Tech Talk Live is the only conference of its kind in the region specifically designed for IT pros in education.
1020 New Holland Avenue, Lancaster, PA 17601