Sunday, June 16, 2024

Managing Exchange CAS IIS Log Files via Script


The Exchange CAS Server will log a large number of transactions. These logs play an important role in troubleshooting, trending as well as a number of other things. However, Exchange or IIS does not provide an option to automatically purge these IIS logs. In this article, I will provide an example to manage these log files.


1.) Create a folder in C:\scripts (or somewhere else) and call it “scheduled”

2.) Download the following ZIP file which included the following *.ps1 Script and place it in the folder above:

$DaysToRetain = 90
$LogFileDirectory = "C:\inetpub\logs\LogFiles"

get-childitem -Path $LogFileDirectory -recurse |
where-object {$_.lastwritetime -lt (get-date).addDays(-$DaysToRetain)} |
Foreach-Object { del $_.FullName }

 3.) Open the task scheduler

4.) Create a new folder called “Exchange”

5.) Now create a new basic task

6.) Give it a Name e.g. “Delete IIS Exchange logfiles”

7.) Choose when to run the task (daily should be fine)

8.) Specify the time when this task should run (see example below)

9.) For the actions select “start a Programm”

10.) In the “Program/script” windows enter then the following (and press next):

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -nologo -NonInteractive -command “. ‘C:\scripts\scheduled\delete_IIS_log_files.ps1’

11.) You will then be asked if you wish to move the comands to the arguments box, so press “yes”

12.) once done press on finish

Depending on your environment you might wish to change the user from the script to the local Administrator account. This can be done in the task properties and ensure that the task is running also when you change your password.


Related Articles


Please enter your comment!
Please enter your name here

Stay Connected

- Advertisement -

Latest Articles