Script pour la purge des logs IIS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
$LogPath = "C:\inetpub\logs\LogFiles\W3SVC1" $maxDaystoKeep = -45 $outputPath = "C:\windows\temp\Purge_log_iis.log" $itemsToDelete = dir $LogPath -File *.log | Where LastWriteTime -lt ((get-date).AddDays($maxDaystoKeep)) $itemsToDelete.VersionInfo.FileName 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 Get-item $item.VersionInfo.FileName | Remove-Item -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 10 |
Cet article n'a pas été revu depuis la publication.
Cet article a été créé par david le 4 octobre 2017.
Laisser un commentaire