Boş safe tespitini ele almıştık. Burada tespit edilen safelerin hızlıca silinmesini de ele alalım. Konu soğumadan tamamlamış olalım.
Yine aynı modülü kullanarak yukarıda tespit edilen safe isimlerini bir txt üzerinde toplayip, o txt üzerinden safeleri tek tek okuyarak silme işlemini gerçekleştirelim.
# Silinecek Safe'lerin bulunduğu TXT dosyası
$SafeListPath = "C:\Temp\RemoveSafe\SafesToDelete.txt"
# Log dosyaları
$SuccessLog = "C:\Temp\RemoveSafe\Deleted_Safes.log"
$ErrorLog = "C:\Temp\RemoveSafe\Failed_Safes.log"
# Önceki logları temizle
Remove-Item -Path $SuccessLog -ErrorAction SilentlyContinue
Remove-Item -Path $ErrorLog -ErrorAction SilentlyContinue
# Eğer TXT dosyası yoksa hata ver
if (!(Test-Path $SafeListPath)) {
Write-Host "HATA: Safe listesi dosyası bulunamadı: $SafeListPath"
}
# TXT dosyasından Safe isimlerini oku
$SafeNames = Get-Content -Path $SafeListPath
# Safe'leri sil
foreach ($SafeName in $SafeNames) {
try {
Write-Host "Siliniyor: $SafeName ..."
Remove-PASSafe -SafeName $SafeName -Confirm:$false
"$SafeName başarıyla silindi." | Out-File -FilePath $SuccessLog -Append
Write-Host "$SafeName başarıyla silindi." -ForegroundColor Green
}
catch {
"$SafeName silinemedi. Hata: $_" | Out-File -FilePath $ErrorLog -Append
Write-Host "$SafeName silinemedi!" -ForegroundColor Red
}
}
Write-Host "Başarıyla silinen Safe'ler: $SuccessLog"
Write-Host "Silinemeyen Safe'ler: $ErrorLog"