Ho creato, con l'aiuto dell' IA, un piccolo programmino in PowerShell. Va salvato in formato .ps1 e quindi eseguito come .\Update.ps1
Si deve eseguire come amministratore e se non lo fate ve lo ricorda. Dalla pulizia dei profili potete escludere i vari utenti che non volete cancellare, basta aggiungerli a quelli preimpostati.
Il programmino esegue l'update di tutte le app tramite WINGET e se non funziona controlla che i vari servizi siano attivi, Esegue la pulizia dei profili utente, comodissimo in ambiente scolastico e poi fa l'update di Windows senza usare la GUI classica ma da riga di comando.
SOS_Global_Fix_Final.ps1
# Incolla qui il contenuto dello script PowerShell
# ----------------------------------------------------------------
# SOS PC SCHOOL FINAL - Fix, Update, Pulizia & Reboot
# ----------------------------------------------------------------
Clear-Host
$host.ui.RawUI.WindowTitle = "SOS Globale FINAL - Assistenza Tecnica"
# Header Grafico
Write-Host "==========================================================" -ForegroundColor Cyan
Write-Host " _____ ____ _____ _____ _ ____ ____ _ " -ForegroundColor Cyan
Write-Host " / ____|/ __ \ / ____| / ____| | / __ \| _ \ /\ | | " -ForegroundColor Cyan
Write-Host " | (___ | | | | (___ | | __| | | | | | |_) | / \ | | " -ForegroundColor Cyan
Write-Host " \___ \| | | |\___ \ | | |_ | | | | | | _ < / /\ \ | | " -ForegroundColor Cyan
Write-Host " ____) | |__| |____) | | |__| | |___| |__| | |_) / ____ \| |____ " -ForegroundColor Cyan
Write-Host " |_____/ \____/|_____/ \_____|______\____/|____/_/ \_\______|" -ForegroundColor Cyan
Write-Host "==========================================================" -ForegroundColor Cyan
Write-Host " FIX REGISTRO + UPDATES + PULIZIA PROFILI + REBOOT " -ForegroundColor Yellow
Write-Host "==========================================================" -ForegroundColor Cyan
# 1. Verifica Privilegi Administrator
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Host " [!] ERRORE: Devi eseguire questo script come AMMINISTRATORE." -ForegroundColor Red
Start-Sleep -Seconds 5
exit
}
# 2. Fix Registro Servizi (AppXSVC, ClipSVC, wuauserv, bits, DoSvc)
Write-Host "[*] Ripristino chiavi di registro per i servizi critici..." -ForegroundColor White
$RegistryPaths = @(
"HKLM:\SYSTEM\CurrentControlSet\Services\AppXSVC",
"HKLM:\SYSTEM\CurrentControlSet\Services\ClipSVC",
"HKLM:\SYSTEM\CurrentControlSet\Services\wuauserv",
"HKLM:\SYSTEM\CurrentControlSet\Services\bits",
"HKLM:\SYSTEM\CurrentControlSet\Services\DoSvc"
)
foreach ($path in $RegistryPaths) {
if (Test-Path $path) {
Set-ItemProperty -Path $path -Name "Start" -Value 2
Write-Host " [+] Reset completato: $($path.Split('\')[-1])" -ForegroundColor Gray
}
}
# 3. Pulizia Profili Studenti (Esclusioni: Amministratore, ECDL, Invalsi)
Write-Host "`n[*] Analisi e pulizia profili utenti locali..." -ForegroundColor Magenta
$Esclusioni = 'Amministratore|ECDL|Invalsi|Public|Default'
$ProfiliDaEliminare = Get-WmiObject -Class Win32_UserProfile | Where-Object {
$_.Special -eq $false -and
$_.LocalPath -notmatch $Esclusioni -and
$_.LastUseTime -lt (Get-Date).AddDays(-1).ToString('yyyyMMddHHmmss.ffffff-000')
}
if ($ProfiliDaEliminare) {
foreach ($Profilo in $ProfiliDaEliminare) {
try {
Write-Host " [-] Rimozione profilo: $($Profilo.LocalPath)" -ForegroundColor Gray
$Profilo.Delete()
} catch {
Write-Host " [!] Errore rimozione $($Profilo.LocalPath) (Profilo in uso)." -ForegroundColor Red
}
}
} else {
Write-Host " [OK] Nessun profilo studente da rimuovere." -ForegroundColor Gray
}
# 4. Configurazione Ambiente e Modulo Update
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process -Force
if (-not (Get-Module -ListAvailable -Name PSWindowsUpdate)) {
Write-Host "`n[+] Installazione componenti per Windows Update..." -ForegroundColor Green
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force | Out-Null
Install-Module PSWindowsUpdate -Force -AllowClobber | Out-Null
}
# 5. Esecuzione Windows Update (Sistema)
Write-Host "`n[*] Avvio Windows Update (Sistema Operativo)..." -ForegroundColor Cyan
try {
Import-Module PSWindowsUpdate
Get-WindowsUpdate -AcceptAll -Install -AutoReboot:$false -ErrorAction SilentlyContinue
} catch {
Write-Host " [!] Errore durante l'update di sistema." -ForegroundColor Red
}
# 6. Esecuzione Winget Update (App di terze parti)
Write-Host "`n[*] Avvio Winget Update (Applicazioni)..." -ForegroundColor Yellow
winget source update --name winget | Out-Null
winget update --all --silent --accept-package-agreements --accept-source-agreements
# 7. Chiusura e Riavvio Automatico
Write-Host "`n==========================================================" -ForegroundColor Cyan
Write-Host " OPERAZIONE COMPLETATA CON SUCCESSO! " -ForegroundColor Green
Write-Host "==========================================================" -ForegroundColor Cyan
Write-Host " Il PC si riavviera' tra 30 secondi." -ForegroundColor Red
Write-Host " Chiudi questa finestra per annullare il riavvio." -ForegroundColor Gray
Start-Sleep -Seconds 30
Restart-Computer -Force
Nessun commento:
Posta un commento