Created
January 15, 2020 11:19
-
-
Save RippieUK/108a49239ae8572774af91b05cc8fafb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
## Copied and cleaned up the script from https://gallery.technet.microsoft.com/Clear-Exchange-2013-Log-71abba44 | |
## Tested on Exchange 2016 | |
$executionPolicy = Get-ExecutionPolicy | |
if ($executionPolicy -ne 'RemoteSigned') { | |
Set-Executionpolicy RemoteSigned -Force | |
} | |
$days = 7 | |
$IISLogPath = "C:\inetpub\logs\LogFiles\" | |
$ExchangeLoggingPath = "C:\Program Files\Microsoft\Exchange Server\V15\Logging\" | |
$ETLLoggingPath = "C:\Program Files\Microsoft\Exchange Server\V15\Bin\Search\Ceres\Diagnostics\ETLTraces\" | |
$ETLLoggingPath2 = "C:\Program Files\Microsoft\Exchange Server\V15\Bin\Search\Ceres\Diagnostics\Logs" | |
Function CleanLogfiles($TargetFolder) | |
{ | |
Write-Host -ForegroundColor Yellow -BackgroundColor Black $TargetFolder | |
if (Test-Path $TargetFolder) { | |
$Now = Get-Date | |
$LastWrite = $Now.AddDays(-$days) | |
$Files = Get-ChildItem $TargetFolder -Recurse | Where-Object { $_.Extension -in '.log', '.blg', '.etl' -and $_.LastWriteTime -le $lastwrite } | Select-Object -ExpandProperty FullName | |
foreach ($File in $Files) | |
{ | |
Write-Host "Deleting file $File" -ForegroundColor "yellow"; | |
try { | |
Remove-Item $File -ErrorAction Stop | |
} | |
catch { | |
Write-Warning -Message $_.Exception.Message | |
} | |
} | |
} | |
else { | |
Write-Host "The folder $TargetFolder doesn't exist! Check the folder path!" -ForegroundColor "red" | |
} | |
} | |
CleanLogfiles($IISLogPath) | |
CleanLogfiles($ExchangeLoggingPath) | |
CleanLogfiles($ETLLoggingPath) | |
CleanLogfiles($ETLLoggingPath2) |
Hey, just wondering if this script might be in a repo for improvements could be written and merged into a pull request?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, one question regarding variable $Targetfolder, what does it represent? function CleanLogfiles ($Targetfolder) but this variable is empty, where do we insert something in this variable?
*update: I see now it is #general variable for function which gets called later on the bottom of the scripts. Thanks any way :)