??param([int]$PurgeDays=14) try{[Console]::OutputEncoding=New-Object System.Text.UTF8Encoding}catch{} $here=$PSScriptRoot; if(-not $here){ $here=Split-Path -Parent $MyInvocation.MyCommand.Path } $root=Split-Path -Parent $here $dirScripts=Join-Path $root 'scripts' $dirQ=Join-Path $dirScripts 'quarantine' if(!(Test-Path $dirQ)){ New-Item -ItemType Directory -Force -Path $dirQ | Out-Null } $today = Get-Date -Format 'yyyyMMdd' $batch = Join-Path $dirQ $today if(!(Test-Path $batch)){ New-Item -ItemType Directory -Force -Path $batch | Out-Null } # d?placer les *.ps1.bad_* r?cents dans le batch du jour Get-ChildItem -LiteralPath $dirScripts -Filter '*.ps1.bad_*' -File -EA SilentlyContinue | ForEach-Object { $dest = Join-Path $batch $_.Name Move-Item -LiteralPath $_.FullName -Destination $dest -Force Write-Host ('[MOVED] '+$_.Name+' -> '+$dest) } # purge des lots trop anciens $cut=(Get-Date).AddDays(-1 * $PurgeDays) Get-ChildItem -LiteralPath $dirQ -Directory -EA SilentlyContinue | Where-Object { $_.Name -match '^\d{8}$' -and $_.LastWriteTime -lt $cut } | ForEach-Object { Remove-Item -LiteralPath $_.FullName -Recurse -Force Write-Host ('[PURGED] '+$_.FullName) }