3e779be6f3
CI / lint (push) Failing after 13m4s
CI / test (3.11, ubuntu-latest) (push) Failing after 2m4s
CI / test (3.13, ubuntu-latest) (push) Successful in 13m30s
CI / test (3.14, ubuntu-latest) (push) Successful in 17m21s
CI / test (3.12, ubuntu-latest) (push) Successful in 17m55s
CI / discover-apps-ps (push) Successful in 1m56s
CI / test (3.9, ubuntu-latest) (push) Successful in 13m17s
CI / test (3.10, ubuntu-latest) (push) Successful in 26m21s
CI / audit (push) Successful in 13m38s
Deploy site / deploy (push) Has been cancelled
CI / test (3.14, ubuntu-24.04-arm) (push) Has been cancelled
105 lines
3.5 KiB
PowerShell
105 lines
3.5 KiB
PowerShell
# SPDX-License-Identifier: MIT
|
|
# winpodx - Windows Update toggle
|
|
# Usage: toggle_updates.ps1 -Action enable|disable|status
|
|
# Runs inside the Windows container only.
|
|
|
|
param(
|
|
[Parameter(Mandatory=$true)]
|
|
[ValidateSet("enable", "disable", "status")]
|
|
[string]$Action
|
|
)
|
|
|
|
$ErrorActionPreference = "SilentlyContinue"
|
|
|
|
$Services = @("wuauserv", "UsoSvc", "WaaSMedicSvc")
|
|
|
|
function Get-UpdateStatus {
|
|
$wuauserv = Get-Service wuauserv -ErrorAction SilentlyContinue
|
|
if ($wuauserv -and $wuauserv.StartType -ne "Disabled") {
|
|
Write-Host "enabled"
|
|
} else {
|
|
Write-Host "disabled"
|
|
}
|
|
}
|
|
|
|
function Disable-Updates {
|
|
Write-Host "[WinPodX] Disabling Windows Update..."
|
|
|
|
foreach ($svc in $Services) {
|
|
Stop-Service $svc -Force -ErrorAction SilentlyContinue
|
|
Set-Service $svc -StartupType Disabled -ErrorAction SilentlyContinue
|
|
}
|
|
|
|
# Block update-related scheduled tasks
|
|
$tasks = @(
|
|
"\Microsoft\Windows\WindowsUpdate\Scheduled Start"
|
|
"\Microsoft\Windows\UpdateOrchestrator\Schedule Scan"
|
|
"\Microsoft\Windows\UpdateOrchestrator\USO_UxBroker"
|
|
)
|
|
foreach ($task in $tasks) {
|
|
schtasks /Change /TN $task /Disable 2>$null
|
|
}
|
|
|
|
# Block Windows Update domains via hosts file (belt and suspenders)
|
|
$hostsFile = "C:\Windows\System32\drivers\etc\hosts"
|
|
$marker = "# winpodx-update-block"
|
|
$blockEntries = @(
|
|
"$marker"
|
|
"0.0.0.0 update.microsoft.com"
|
|
"0.0.0.0 windowsupdate.microsoft.com"
|
|
"0.0.0.0 download.windowsupdate.com"
|
|
"0.0.0.0 dl.delivery.mp.microsoft.com"
|
|
"0.0.0.0 ctldl.windowsupdate.com"
|
|
"$marker-end"
|
|
)
|
|
|
|
# Remove existing block if present, then add
|
|
$content = Get-Content $hostsFile -ErrorAction SilentlyContinue | Where-Object {
|
|
$_ -notmatch "winpodx-update-block" -and
|
|
$_ -notmatch "^0\.0\.0\.0.*(update\.microsoft|windowsupdate|dl\.delivery)"
|
|
}
|
|
$content += $blockEntries
|
|
# -Encoding ASCII: PS 5.1 defaults to locale-ANSI (non-portable) and PS 7
|
|
# writes UTF-8 with BOM, which the Windows DNS client refuses to parse.
|
|
# ASCII is the only encoding the hosts resolver has accepted since XP.
|
|
Set-Content -Path $hostsFile -Value $content -Encoding ASCII -Force
|
|
|
|
Write-Host "[WinPodX] Windows Update disabled"
|
|
}
|
|
|
|
function Enable-Updates {
|
|
Write-Host "[WinPodX] Enabling Windows Update..."
|
|
|
|
foreach ($svc in $Services) {
|
|
Set-Service $svc -StartupType Manual -ErrorAction SilentlyContinue
|
|
Start-Service $svc -ErrorAction SilentlyContinue
|
|
}
|
|
|
|
# Re-enable scheduled tasks
|
|
$tasks = @(
|
|
"\Microsoft\Windows\WindowsUpdate\Scheduled Start"
|
|
"\Microsoft\Windows\UpdateOrchestrator\Schedule Scan"
|
|
"\Microsoft\Windows\UpdateOrchestrator\USO_UxBroker"
|
|
)
|
|
foreach ($task in $tasks) {
|
|
schtasks /Change /TN $task /Enable 2>$null
|
|
}
|
|
|
|
# Remove hosts file block
|
|
$hostsFile = "C:\Windows\System32\drivers\etc\hosts"
|
|
$content = Get-Content $hostsFile -ErrorAction SilentlyContinue | Where-Object {
|
|
$_ -notmatch "winpodx-update-block" -and
|
|
$_ -notmatch "^0\.0\.0\.0.*(update\.microsoft|windowsupdate|dl\.delivery)"
|
|
}
|
|
# -Encoding ASCII: hosts file must stay ASCII so the DNS client parses it on both PS 5.1 and PS 7.
|
|
Set-Content -Path $hostsFile -Value $content -Encoding ASCII -Force
|
|
|
|
Write-Host "[WinPodX] Windows Update enabled"
|
|
}
|
|
|
|
switch ($Action) {
|
|
"enable" { Enable-Updates }
|
|
"disable" { Disable-Updates }
|
|
"status" { Get-UpdateStatus }
|
|
}
|