Aggiunta script pulizia log IIS

This commit is contained in:
Samuele Locatelli
2024-02-15 16:13:04 +01:00
parent 4a902ad6f8
commit a9c0f5fbd8
+20
View File
@@ -0,0 +1,20 @@
$LogPath = "C:\inetpub\logs"
$maxDaystoKeep = -90
$outputPath = "C:\Steamware\Logs\Cleanup_Logs.log"
Write-Output "Start Cleanup" > $outputPath
$itemsToDelete = dir $LogPath -Recurse -File *.log | Where LastWriteTime -lt ((get-date).AddDays($maxDaystoKeep))
if ($itemsToDelete.Count -gt 0){
ForEach ($item in $itemsToDelete){
"$($item.BaseName) is older than $((get-date).AddDays($maxDaystoKeep)) and will be deleted" | Add-Content $outputPath
Remove-Item $item.FullName -Verbose
}
}
ELSE{
"No items to be deleted today $($(Get-Date).DateTime)" | Add-Content $outputPath
}
Write-Output "Cleanup of log files older than $((get-date).AddDays($maxDaystoKeep)) completed..."
start-sleep -Seconds 3