Our exchange server creates a ridiculous amount of log files that if gone unchecked over a work week will pretty much kill email until said logs are deleted.

i would like to set up a task on our exchange server to delete all .log files in a particular folder (for example Drive E and the folder is called \microsoft exchange\log files\these need deleted) in the date range of everything before 3 days ago, so going by todays date i would like it to delete all log files in that directory earlier than the 23rd of oct.

any ideas, i am more figuring out hardware and the simpler side of network stuff and powershell is sill a bit new to me

5 Spice ups

There are scripts out there which will do this but are these Exchange text based log files or Exchange TRANSACTION log files?

This script will give you a starting point http://stackoverflow.com/questions/17829785/delete-files-older-than-15-days-using-powershell

1 Spice up

many thanks

looking at the various answers and links I got to this one

Delete all files created more than 2 days ago.

Remove-FilesCreatedBeforeDate -Path “C:\Some\Directory” -DateTime ((Get-Date).AddDays(-2)) -DeletePathIfEmpty

this looks perfect but how can I limit it to only delete *.log files within this time frame?

change the path to be -Path “c:\some\directory*.log” and see if that works.

If it were me, I’d be using a Get/Remove pattern something like this:

$Path    = 'C:\Some\Folder\'
$OldDate = (Get-Date).AddDays(-2)
Get-ChildItem -Path $Path -Include *.log | Where LastAccessTime -lt $OldDate | Remove-Item
4 Spice ups

thank you both for your help

since I went and manually deleted these to get our email working again I will try tomorrow morning and give an update

again, much appreciated with your input