Created
February 11, 2016 19:16
-
-
Save BretFisher/68fe60ac4f0c94bc8086 to your computer and use it in GitHub Desktop.
Exchange 2013 Log Cleanup PowerShell Script
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=10 #You can change the number of days here | |
$IISLogPath="C:\inetpub\logs\" | |
$ExchangeLoggingPath="C:\Program Files\Microsoft\Exchange Server\V15\Logging\" | |
Function CleanLogfiles($TargetFolder) | |
{ | |
if (Test-Path $TargetFolder) { | |
$Now = Get-Date | |
$LastWrite = $Now.AddDays(-$days) | |
$Files = Get-ChildItem $TargetFolder -Include *.log,*.blg -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" | |
} | |
} | |
# lets do this | |
Write-Host "Removing IIS and Exchange logs; keeping last" $days "days" | |
CleanLogfiles($IISLogPath) | |
CleanLogfiles($ExchangeLoggingPath) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment