cleanExchangeLogs.ps1 hinzugefügt
This commit is contained in:
parent
2090031ea0
commit
7ac8da84a1
1 changed files with 41 additions and 0 deletions
41
cleanExchangeLogs.ps1
Normal file
41
cleanExchangeLogs.ps1
Normal file
|
@ -0,0 +1,41 @@
|
|||
$executionPolicy = Get-ExecutionPolicy
|
||||
if ($executionPolicy -ne 'RemoteSigned') {
|
||||
Set-Executionpolicy RemoteSigned -Force
|
||||
}
|
||||
|
||||
$days = 2
|
||||
$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)
|
Loading…
Add table
Add a link
Reference in a new issue