enotkrutoy commited on
Commit
6fcac01
·
verified ·
1 Parent(s): 80ee66d

Create Invoke-StealthClean.ps1

Browse files
Files changed (1) hide show
  1. Invoke-StealthClean.ps1 +85 -0
Invoke-StealthClean.ps1 ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #IEX (New-Object Net.WebClient).DownloadString('https://huggingface.co/spaces/enotkrutoy/search/resolve/main/Invoke-StealthClean.ps1')
2
+ # Скрытный режим (по умолчанию)
3
+ #Invoke-StealthClean
4
+
5
+ # Режим отладки (с сохранением лога)
6
+ #Invoke-StealthClean -DebugMode -LogPath "$env:TEMP\cleanup.log"
7
+
8
+ function Invoke-StealthClean {
9
+ param(
10
+ [string]$LogPath = "$env:TEMP\~tmp$(Get-Random).log",
11
+ [switch]$DebugMode
12
+ )
13
+
14
+ # Скрытое логирование
15
+ function Write-Log ($Message) {
16
+ $Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
17
+ $Entry = "[$Timestamp] $Message"
18
+ try {
19
+ $Entry | Out-File -FilePath $LogPath -Append -Encoding UTF8 -ErrorAction Stop
20
+ } catch {}
21
+ if ($DebugMode) { Write-Host $Entry }
22
+ }
23
+
24
+ # Безопасное удаление
25
+ function Remove-Silent {
26
+ param($Path)
27
+ try {
28
+ if (Test-Path $Path) {
29
+ Get-ChildItem $Path -Force -ErrorAction Stop | Remove-Item -Recurse -Force -ErrorAction Stop
30
+ Write-Log "Purged: $Path"
31
+ return $true
32
+ }
33
+ } catch { Write-Log "Failed: $Path | $($_.Exception.Message)" }
34
+ return $false
35
+ }
36
+
37
+ Write-Log "=== CLEANUP STARTED ==="
38
+
39
+ # 1. Системные временные файлы
40
+ @(
41
+ $env:TEMP,
42
+ "$env:SystemRoot\Temp",
43
+ "$env:SystemRoot\SoftwareDistribution\Download",
44
+ "$env:SystemRoot\Prefetch"
45
+ ) | ForEach-Object { Remove-Silent $_ }
46
+
47
+ # 2. Журналы событий (избирательная очистка)
48
+ $ProtectedLogs = @('Microsoft-Windows-LiveId*', 'USBVideo*', 'Security')
49
+ wevtutil el | Where-Object { $_ -notin $ProtectedLogs } | ForEach-Object {
50
+ try {
51
+ wevtutil cl $_ | Out-Null
52
+ Write-Log "Cleared log: $_"
53
+ } catch { Write-Log "Skipped log: $_" }
54
+ }
55
+
56
+ # 3. Кэш браузеров (включая резервные копии)
57
+ $BrowserTargets = @(
58
+ "$env:LOCALAPPDATA\Google\Chrome\User Data\Default\*Cache*",
59
+ "$env:LOCALAPPDATA\Microsoft\Edge\User Data\Default\*Cache*",
60
+ "$env:APPDATA\Mozilla\Firefox\Profiles\*.default-release\cache2",
61
+ "$env:USERPROFILE\AppData\Roaming\Opera Software\Opera Stable\Cache"
62
+ )
63
+ $BrowserTargets | ForEach-Object { Remove-Silent $_ }
64
+
65
+ # 4. Автоматическая очистка диска
66
+ if (Test-Path "$env:SystemRoot\System32\cleanmgr.exe") {
67
+ $CleanArgs = @(
68
+ "/d $env:SystemDrive",
69
+ "/sagerun:1",
70
+ "/quiet"
71
+ )
72
+ Start-Process -WindowStyle Hidden -FilePath "cleanmgr.exe" -ArgumentList $CleanArgs -Wait
73
+ Write-Log "Disk cleanup executed"
74
+ }
75
+
76
+ # 5. Очистка следов
77
+ if (-not $DebugMode) {
78
+ Remove-Silent $LogPath
79
+ [System.GC]::Collect()
80
+ }
81
+
82
+ Write-Log "=== CLEANUP COMPLETED ==="
83
+ }
84
+
85
+ Invoke-StealthClean