Skip to content

Instantly share code, notes, and snippets.

@raspberrypisig
Last active June 18, 2025 01:06
Show Gist options
  • Save raspberrypisig/86c9c6a28d2debe59d89a6fe73ed75c9 to your computer and use it in GitHub Desktop.
Save raspberrypisig/86c9c6a28d2debe59d89a6fe73ed75c9 to your computer and use it in GitHub Desktop.
#requires -RunAsAdministrator
$serviceName = "wuauserv"
Write-Host "--- Stopping and Disabling the Windows Update Service ---" -ForegroundColor Cyan
try {
$service = Get-Service -Name $serviceName -ErrorAction Stop
if ($service.Status -eq 'Running') {
Write-Host "Stopping service: $($service.DisplayName)..." -ForegroundColor Yellow
Stop-Service -Name $serviceName -Force -PassThru | Wait-Service -Timeout 60
Write-Host "Service has been stopped." -ForegroundColor Green
}
else {
Write-Host "Service is already stopped." -ForegroundColor Green
}
#$currentStartType = (Get-CimInstance -ClassName Win32_Service -Filter "Name='$serviceName'").StartMode
$currentStartType = $service.StartType
if ($currentStartType -ne 'Disabled') {
Write-Host "Disabling service: $($service.DisplayName)..." -ForegroundColor Yellow
Set-Service -Name $serviceName -StartupType Disabled
Write-Host "Service has been disabled." -ForegroundColor Green
}
else {
Write-Host "Service is already disabled." -ForegroundColor Green
}
}
catch {
Write-Host -ForegroundColor Red "An error occurred: $($_.Exception.Message)"
exit 1
}
Write-Host "`n--- Final Status Verification ---" -ForegroundColor Cyan
Get-Service -Name $serviceName | Format-List Name, DisplayName, Status, StartType
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment