import depuis ancien GitHub
This commit is contained in:
18
maintenance-delete-IIS-logs/Purge-IISLogs.ps1
Normal file
18
maintenance-delete-IIS-logs/Purge-IISLogs.ps1
Normal file
@@ -0,0 +1,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
|
||||
24
maintenance-delete-IIS-logs/readme.md
Normal file
24
maintenance-delete-IIS-logs/readme.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# Purge IIS Logs (PowerShell)
|
||||
|
||||
Purge old IIS log files to prevent the C: drive from filling up (IIS logs are stored by default under `%SystemDrive%\inetpub\logs\LogFiles`). :contentReference[oaicite:0]{index=0}
|
||||
|
||||
|
||||
|
||||
## Usage
|
||||
Edit these variables :
|
||||
```powershell
|
||||
$LogPath
|
||||
$maxDaystoKeep
|
||||
$outputPath
|
||||
```
|
||||
Run from an elevated PowerShell prompt on the IIS server.
|
||||
|
||||
## Schedule (Task Scheduler)
|
||||

|
||||
|
||||
Run weekly as SYSTEM (example: Sundays 02:00):
|
||||
```powershell
|
||||
schtasks /Create /TN "IIS Logs Purge" ^
|
||||
/TR "powershell.exe -NoProfile -ExecutionPolicy Bypass -File C:\Scripts\Purge-IISLogs.ps1" ^
|
||||
/SC WEEKLY /D SUN /ST 02:00 /RU SYSTEM /RL HIGHEST /F
|
||||
```
|
||||
BIN
maintenance-delete-IIS-logs/readme.png
Normal file
BIN
maintenance-delete-IIS-logs/readme.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 165 KiB |
Reference in New Issue
Block a user