165 lines
9.3 KiB
PowerShell
165 lines
9.3 KiB
PowerShell
# =============================================================================
|
|
# scan_cleanup_v1.0.ps1
|
|
# Verze: 1.0
|
|
# Datum: 2026-06-15
|
|
# Autor: Vladimír Buzalka (s asistencí Claude)
|
|
# Popis: READ-ONLY skener volného místa na disku pro účet bez admin práv.
|
|
# NIC NEMAŽE. Pouze proskenuje typická "user-space" místa, kde lze
|
|
# uklízet bez administrátorských oprávnění, a vypíše přehled
|
|
# seřazený podle velikosti + návrhy co smazat. Na konci ukáže
|
|
# přesné příkazy pro skutečné smazání (musíš je spustit ručně).
|
|
#
|
|
# Spuštění (z PowerShellu, NEpotřebuje admina):
|
|
# powershell -ExecutionPolicy Bypass -File .\scan_cleanup_v1.0.ps1
|
|
# Volitelně uložení reportu do souboru:
|
|
# powershell -ExecutionPolicy Bypass -File .\scan_cleanup_v1.0.ps1 *> report.txt
|
|
# =============================================================================
|
|
|
|
$ErrorActionPreference = 'SilentlyContinue'
|
|
$ProgressPreference = 'SilentlyContinue'
|
|
|
|
function Format-Size {
|
|
param([long]$Bytes)
|
|
if ($Bytes -ge 1GB) { return ('{0:N2} GB' -f ($Bytes / 1GB)) }
|
|
if ($Bytes -ge 1MB) { return ('{0:N1} MB' -f ($Bytes / 1MB)) }
|
|
if ($Bytes -ge 1KB) { return ('{0:N0} KB' -f ($Bytes / 1KB)) }
|
|
return "$Bytes B"
|
|
}
|
|
|
|
function Get-FolderSize {
|
|
param([string]$Path)
|
|
if (-not (Test-Path -LiteralPath $Path)) { return $null }
|
|
$files = Get-ChildItem -LiteralPath $Path -Recurse -Force -File -ErrorAction SilentlyContinue
|
|
if (-not $files) { return [pscustomobject]@{ Bytes = 0; Count = 0 } }
|
|
$sum = ($files | Measure-Object -Property Length -Sum)
|
|
return [pscustomobject]@{
|
|
Bytes = [long]($sum.Sum)
|
|
Count = [int]$sum.Count
|
|
}
|
|
}
|
|
|
|
# --- Hlavička / info o disku -------------------------------------------------
|
|
Write-Host ""
|
|
Write-Host "===========================================================" -ForegroundColor Cyan
|
|
Write-Host " SKEN MOZNOSTI UKLIDU DISKU (read-only, bez admina)" -ForegroundColor Cyan
|
|
Write-Host " Pocitac: $env:COMPUTERNAME Uzivatel: $env:USERNAME" -ForegroundColor Cyan
|
|
Write-Host " Cas: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')" -ForegroundColor Cyan
|
|
Write-Host "===========================================================" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
|
|
# Volné místo na systémovém disku
|
|
$sysDrive = (Get-Item $env:SystemDrive)
|
|
$drive = Get-PSDrive -Name $sysDrive.Name.TrimEnd(':') -ErrorAction SilentlyContinue
|
|
if ($drive) {
|
|
$free = $drive.Free
|
|
$used = $drive.Used
|
|
$total = $free + $used
|
|
Write-Host ("Disk {0} celkem: {1} volne: {2} obsazeno: {3}" -f `
|
|
$env:SystemDrive, (Format-Size $total), (Format-Size $free), (Format-Size $used)) -ForegroundColor Yellow
|
|
Write-Host ""
|
|
}
|
|
|
|
# --- Kandidatske lokace (vse v ramci uzivatelskeho profilu = bez admina) -----
|
|
# Bezpecne smazatelne (cache / temp / koš)
|
|
$candidates = @(
|
|
@{ Name = 'Uzivatelsky TEMP'; Path = $env:TEMP; Safe = $true }
|
|
@{ Name = 'Windows Temp (user)'; Path = (Join-Path $env:LOCALAPPDATA 'Temp'); Safe = $true }
|
|
@{ Name = 'INetCache (IE/Win)'; Path = (Join-Path $env:LOCALAPPDATA 'Microsoft\Windows\INetCache'); Safe = $true }
|
|
@{ Name = 'WER - chybove reporty'; Path = (Join-Path $env:LOCALAPPDATA 'Microsoft\Windows\WER'); Safe = $true }
|
|
@{ Name = 'Explorer thumbnail cache'; Path = (Join-Path $env:LOCALAPPDATA 'Microsoft\Windows\Explorer'); Safe = $true }
|
|
@{ Name = 'Chrome - Cache'; Path = (Join-Path $env:LOCALAPPDATA 'Google\Chrome\User Data\Default\Cache'); Safe = $true }
|
|
@{ Name = 'Chrome - Code Cache'; Path = (Join-Path $env:LOCALAPPDATA 'Google\Chrome\User Data\Default\Code Cache'); Safe = $true }
|
|
@{ Name = 'Chrome - GPUCache'; Path = (Join-Path $env:LOCALAPPDATA 'Google\Chrome\User Data\Default\GPUCache'); Safe = $true }
|
|
@{ Name = 'Edge - Cache'; Path = (Join-Path $env:LOCALAPPDATA 'Microsoft\Edge\User Data\Default\Cache'); Safe = $true }
|
|
@{ Name = 'Edge - Code Cache'; Path = (Join-Path $env:LOCALAPPDATA 'Microsoft\Edge\User Data\Default\Code Cache'); Safe = $true }
|
|
@{ Name = 'Firefox - cache2'; Path = (Join-Path $env:LOCALAPPDATA 'Mozilla\Firefox\Profiles'); Safe = $true }
|
|
@{ Name = 'Teams - cache (classic)'; Path = (Join-Path $env:APPDATA 'Microsoft\Teams'); Safe = $true }
|
|
@{ Name = 'Teams - cache (new)'; Path = (Join-Path $env:LOCALAPPDATA 'Packages\MSTeams_8wekyb3d8bbwe\LocalCache'); Safe = $true }
|
|
@{ Name = 'Office - dokumentova cache'; Path = (Join-Path $env:LOCALAPPDATA 'Microsoft\Office\16.0\OfficeFileCache'); Safe = $true }
|
|
@{ Name = 'pip cache (Python)'; Path = (Join-Path $env:LOCALAPPDATA 'pip\Cache'); Safe = $true }
|
|
@{ Name = 'Playwright browsers cache'; Path = (Join-Path $env:LOCALAPPDATA 'ms-playwright'); Safe = $true }
|
|
@{ Name = 'npm cache'; Path = (Join-Path $env:LOCALAPPDATA 'npm-cache'); Safe = $true }
|
|
@{ Name = 'NuGet cache'; Path = (Join-Path $env:USERPROFILE '.nuget\packages'); Safe = $true }
|
|
@{ Name = 'Spotify - Storage'; Path = (Join-Path $env:LOCALAPPDATA 'Spotify\Storage'); Safe = $true }
|
|
@{ Name = 'CrashDumps'; Path = (Join-Path $env:LOCALAPPDATA 'CrashDumps'); Safe = $true }
|
|
)
|
|
|
|
# Zkontrolovat ale NEMAZAT automaticky (uzivatel musi posoudit obsah)
|
|
$review = @(
|
|
@{ Name = 'Slozka Downloads (stahovani)'; Path = (Join-Path $env:USERPROFILE 'Downloads') }
|
|
@{ Name = 'Plocha (Desktop)'; Path = (Join-Path $env:USERPROFILE 'Desktop') }
|
|
@{ Name = 'Dokumenty'; Path = (Join-Path $env:USERPROFILE 'Documents') }
|
|
@{ Name = 'Kos (Recycle Bin)'; Path = (Join-Path $env:SystemDrive '\$Recycle.Bin') }
|
|
)
|
|
|
|
Write-Host "--- BEZPECNE SMAZATELNE (cache / temp) --------------------" -ForegroundColor Green
|
|
$results = @()
|
|
foreach ($c in $candidates) {
|
|
$info = Get-FolderSize -Path $c.Path
|
|
if ($info -and $info.Bytes -gt 0) {
|
|
$results += [pscustomobject]@{
|
|
Name = $c.Name
|
|
Path = $c.Path
|
|
Bytes = $info.Bytes
|
|
Count = $info.Count
|
|
}
|
|
}
|
|
}
|
|
|
|
$totalSafe = 0
|
|
foreach ($r in ($results | Sort-Object Bytes -Descending)) {
|
|
$totalSafe += $r.Bytes
|
|
Write-Host (" {0,10} {1,7} souboru {2}" -f (Format-Size $r.Bytes), $r.Count, $r.Name)
|
|
Write-Host (" -> {0}" -f $r.Path) -ForegroundColor DarkGray
|
|
}
|
|
if ($results.Count -eq 0) { Write-Host " (nic vyznamneho nenalezeno)" -ForegroundColor DarkGray }
|
|
|
|
Write-Host ""
|
|
Write-Host (" >>> POTENCIAL CACHE/TEMP CELKEM: {0}" -f (Format-Size $totalSafe)) -ForegroundColor Green
|
|
Write-Host ""
|
|
|
|
Write-Host "--- K RUCNI KONTROLE (NEMAZAT automaticky) ----------------" -ForegroundColor Yellow
|
|
foreach ($c in ($review)) {
|
|
$info = Get-FolderSize -Path $c.Path
|
|
if ($info) {
|
|
Write-Host (" {0,10} {1,7} souboru {2}" -f (Format-Size $info.Bytes), $info.Count, $c.Name)
|
|
Write-Host (" -> {0}" -f $c.Path) -ForegroundColor DarkGray
|
|
}
|
|
}
|
|
Write-Host ""
|
|
|
|
# --- TOP velke soubory v profilu (>100 MB) -----------------------------------
|
|
Write-Host "--- 20 NEJVETSICH SOUBORU V PROFILU (>100 MB) -------------" -ForegroundColor Magenta
|
|
$big = Get-ChildItem -LiteralPath $env:USERPROFILE -Recurse -Force -File -ErrorAction SilentlyContinue |
|
|
Where-Object { $_.Length -gt 100MB } |
|
|
Sort-Object Length -Descending |
|
|
Select-Object -First 20
|
|
if ($big) {
|
|
foreach ($f in $big) {
|
|
Write-Host (" {0,10} {1}" -f (Format-Size $f.Length), $f.FullName)
|
|
}
|
|
} else {
|
|
Write-Host " (zadne soubory nad 100 MB)" -ForegroundColor DarkGray
|
|
}
|
|
Write-Host ""
|
|
|
|
# --- Navod na skutecne smazani ----------------------------------------------
|
|
Write-Host "===========================================================" -ForegroundColor Cyan
|
|
Write-Host " JAK SKUTECNE SMAZAT (spustit RUCNE, az po kontrole):" -ForegroundColor Cyan
|
|
Write-Host "===========================================================" -ForegroundColor Cyan
|
|
Write-Host @"
|
|
# Vyprazdneni kose:
|
|
Clear-RecycleBin -Force
|
|
|
|
# Smazani obsahu uzivatelskeho TEMP (zavri aplikace; nektere zamcene soubory zustanou):
|
|
Get-ChildItem -LiteralPath `$env:TEMP -Recurse -Force -ErrorAction SilentlyContinue |
|
|
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
|
|
|
|
# Smazani konkretni cache slozky (priklad Chrome) - prohlizec MUSI byt zavreny:
|
|
Remove-Item -LiteralPath "`$env:LOCALAPPDATA\Google\Chrome\User Data\Default\Cache\*" -Recurse -Force -ErrorAction SilentlyContinue
|
|
|
|
# Spravce mista ve Windows (bez admina): Nastaveni > System > Uloziste
|
|
"@ -ForegroundColor Gray
|
|
Write-Host ""
|
|
Write-Host "Hotovo. Skript NIC nesmazal - jen vypsal prehled." -ForegroundColor Green
|