Last active
August 29, 2015 13:57
-
-
Save djdefi/9677959 to your computer and use it in GitHub Desktop.
Powershell script to clean out Exchange 2013 log files - Taken from http://www.c7solutions.com/2013/04/removing-old-exchange-2013-log-files-html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Set-Executionpolicy RemoteSigned | |
$days=30 #You can change the number of days here | |
$IISLogPath="C:\inetpub\logs\LogFiles\" | |
$ExchangeLoggingPath="C:\Program Files\Microsoft\Exchange Server\V15\Logging\" | |
Write-Host "Removing IIS and Exchange logs; keeping last" $days "days" | |
Function CleanLogfiles($TargetFolder) | |
{ | |
if (Test-Path $TargetFolder) { | |
$Now = Get-Date | |
$LastWrite = $Now.AddDays(-$days) | |
$Files = Get-ChildItem $TargetFolder -Include *.* -Recurse | Where {$_.LastWriteTime -le "$LastWrite"} | |
foreach ($File in $Files) | |
{Write-Host "Deleting file $File" -ForegroundColor "Red"; Remove-Item $File -ErrorAction SilentlyContinue | out-null} | |
} | |
Else { | |
Write-Host "The folder $TargetFolder doesn't exist! Check the folder path!" -ForegroundColor "red" | |
} | |
} | |
CleanLogfiles($IISLogPath) | |
CleanLogfiles($ExchangeLoggingPath) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment