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
4 changes: 2 additions & 2 deletions CleanupAndUpdateEverything.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,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 +99,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
23 changes: 17 additions & 6 deletions CleanupAndUpdateEverything.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ param (
Write-Host "Iniciando processo automatizado..." -ForegroundColor Green

# --- FUNÇÕES ---
function Confirm-Action {
param(
[string]$Prompt,
[scriptblock]$Action
)
$choice = Read-Host $Prompt
if ($choice -eq "S") {
& $Action
}
}

function Safe-Remove {
param([string]$Path)
Remove-Item -Path $Path -Recurse -Force -ErrorAction SilentlyContinue
Expand Down Expand Up @@ -74,17 +85,17 @@ Write-Host "`n" + "="*60 -ForegroundColor Yellow
Write-Host "MANUTENÇÃO CONCLUÍDA. REVISÃO DE AÇÕES PENDENTES:" -ForegroundColor Yellow
Write-Host "="*60 -ForegroundColor Yellow

$checkDisk = Read-Host "Deseja agendar CHKDSK para o próximo boot? (S/N)"
if ($checkDisk -eq "S") { Write-Output y | & "$env:windir\System32\chkdsk.exe" C: /f /r }
Confirm-Action -Prompt "Deseja agendar CHKDSK para o próximo boot? (S/N)" -Action { Write-Output y | & "$env:windir\System32\chkdsk.exe" C: /f /r }


Confirm-Action -Prompt "Deseja abrir a Microsoft Store? (S/N)" -Action { Start-Process "ms-windows-store://downloadsandupdates" }

$openStore = Read-Host "Deseja abrir a Microsoft Store? (S/N)"
if ($openStore -eq "S") { Start-Process "ms-windows-store://downloadsandupdates" }

$RebootPending = Test-Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending"
if ($RebootPending) {
Write-Host "`n[!] REBOOT NECESSÁRIO!" -ForegroundColor Red
$rebootChoice = Read-Host "Reiniciar agora? (S/N)"
if ($rebootChoice -eq "S") { Restart-Computer -Force }
Confirm-Action -Prompt "Reiniciar agora? (S/N)" -Action { Restart-Computer -Force }

}

Write-Host "`nProcesso finalizado."