Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions CleanupAndUpdateEverything.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
BeforeAll {
BeforeAll {
$env:windir = 'C:\Windows'
$env:LOCALAPPDATA = 'C:\Users\TestUser\AppData\Local'
$sysDir = if ($env:windir) { "$env:windir\System32" } else { "C:\Windows\System32" }
$wingetPath = if ($env:LOCALAPPDATA) { "$env:LOCALAPPDATA\Microsoft\WindowsApps\winget.exe" } else { "C:\Users\Default\AppData\Local\Microsoft\WindowsApps\winget.exe" }

Expand Down Expand Up @@ -90,7 +92,7 @@ Describe "CleanupAndUpdateEverything.ps1" {
# Arrange
Mock Test-Path { return $true } # Make it think reboot is pending
Mock Read-Host { return "N" } # Make it answer 'N' to prompts
Mock chkdsk {}
Mock "$sysDir\chkdsk.exe" {}
Mock Start-Process {}
Mock Restart-Computer {}

Expand All @@ -99,7 +101,7 @@ Describe "CleanupAndUpdateEverything.ps1" {

# Assert
Should -Invoke -CommandName Read-Host -Times 3
Should -Invoke -CommandName chkdsk -Times 0
Should -Invoke -CommandName "$sysDir\chkdsk.exe" -Times 0
Should -Invoke -CommandName Start-Process -Times 0
Should -Invoke -CommandName Restart-Computer -Times 0
}
Expand Down
17 changes: 11 additions & 6 deletions CleanupAndUpdateEverything.ps1
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
param (
param (
[switch]$SilentMode
)

Write-Host "Iniciando processo automatizado..." -ForegroundColor Green

# --- FUNÇÕES ---
function Write-SectionHeader {
param([string]$Title)
Write-Host "`n=== $Title ===" -ForegroundColor Magenta
}

function Safe-Remove {
param([string]$Path)
Remove-Item -Path $Path -Recurse -Force -ErrorAction SilentlyContinue
Expand All @@ -14,7 +19,7 @@ function Safe-Remove {
}

# === 1. LIMPEZAS E CACHE ===
Write-Host "`n=== 1. Limpeza de Arquivos Temporários ===" -ForegroundColor Magenta
Write-SectionHeader "1. Limpeza de Arquivos Temporários"
Safe-Remove "$env:TEMP\*"
Safe-Remove "$env:windir\Temp\*"
Safe-Remove "$env:windir\Prefetch\*"
Expand All @@ -29,13 +34,13 @@ Write-Host "Esvaziando Lixeira..." -ForegroundColor Cyan
Clear-RecycleBin -Force

# === 2. REPARO DE SISTEMA (DISM & SFC) ===
Write-Host "`n=== 2. Reparo de Imagem e Arquivos (DISM/SFC) ===" -ForegroundColor Magenta
Write-SectionHeader "2. Reparo de Imagem e Arquivos (DISM/SFC)"
& "$env:windir\System32\dism.exe" /Online /Cleanup-Image /RestoreHealth
& "$env:windir\System32\dism.exe" /Online /Cleanup-Image /StartComponentCleanup /ResetBase
& "$env:windir\System32\sfc.exe" /scannow

# === 3. REDE E CONECTIVIDADE ===
Write-Host "`n=== 3. Reset de Rede e DNS ===" -ForegroundColor Magenta
Write-SectionHeader "3. Reset de Rede e DNS"
& {
& "$env:windir\System32\ipconfig.exe" /flushdns
& "$env:windir\System32\ipconfig.exe" /release
Expand All @@ -46,7 +51,7 @@ Write-Host "`n=== 3. Reset de Rede e DNS ===" -ForegroundColor Magenta
Write-Host "Rede resetada com sucesso." -ForegroundColor Green

# === 4. ATUALIZAÇÕES (Winget & Windows) ===
Write-Host "`n=== 4. Atualizacoes Silenciosas ===" -ForegroundColor Magenta
Write-SectionHeader "4. Atualizacoes Silenciosas"
& "$env:LOCALAPPDATA\Microsoft\WindowsApps\winget.exe" upgrade --all --silent --accept-package-agreements --accept-source-agreements

if (Get-Module -ListAvailable -Name PSWindowsUpdate) {
Expand All @@ -59,7 +64,7 @@ if (Get-Module -ListAvailable -Name PSWindowsUpdate) {
}

# === 5. OTIMIZAÇÃO DE DISCO (SSD/HDD) ===
Write-Host "`n=== 5. Otimizacao de Volume ===" -ForegroundColor Magenta
Write-SectionHeader "5. Otimizacao de Volume"
Optimize-Volume -DriveLetter C -ReTrim -Defrag

# ============================================================
Expand Down