Public/ps1/Log/Log-Management.ps1
function Log-Management { if ($LogManagement) { Load-LogConfiguration } $logFile = $LogManagement.LogFolder $lastWrite = (get-item $logFile).LastWriteTime $timespan = new-timespan -hours ($LogManagement.Hours) if (((get-date) - $lastWrite) -gt $timespan) { # older Move-LogFile } else { # newer } if ((Get-ChildItem ($logFile+"*") | Measure-Object).Count -gt $LogManagement.LogRetention) { $files = Get-ChildItem ($logFile+"*") $file = ($files.Name | Where-Object {$_.Contains("_")} |Sort-Object {$_})[0] $fileToDelete = Get-ChildItem ($logFile+"_"+$file.Split("_")[1]) Remove-Item $fileToDelete.FullName } } |