Last active
March 13, 2021 13:03
-
-
Save MaySoMusician/23c6943a5393c87161a6fffa544dbf3e to your computer and use it in GitHub Desktop.
How to *hide* (prevent Windows from installing) the particular updates with Powershell. https://qiita.com/MaySoMusician/items/f239197283f4a8ad9811
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Requires -RunAsAdministrator | |
# Must run this as an administrator! | |
# Based on the official wushowhide.diagcab | |
$target = "2021-03 Cumulative Update for Windows 10 Version 20H2 for x64-based Systems (KB5000802)" | |
Write-Host "" | |
Write-Host "This program will *hide* (prevent Windows from installing) the following update" | |
Write-Host " - '$target'." | |
Write-Host "" | |
Write-Host -NoNewLine "Are you sure you want to proceed? (y/N) " | |
$confirm = [System.Console]::ReadKey() | |
Write-Host "" | |
if ($confirm.Key -ne "Y") { | |
Write-Host "" | |
Write-Host Operation cancelled. | |
exit 1 | |
} | |
Write-Host "" | |
Write-Host "Operation started." | |
Write-Host "" | |
Write-Host "Searching the update..." | |
$session = New-Object -ComObject Microsoft.Update.Session | |
$searcher = $session.CreateUpdateSearcher() | |
$updates = $searcher.Search("IsInstalled=0").Updates | |
$run = $false | |
foreach($update in $updates){ | |
if ($update.Title -eq $target){ | |
Write-Verbose "Attempting to hide $(($update).Title)" | |
$update.IsHidden = $true | |
Write-Verbose "Set IsHidden to '$($update).IsHidden)'" | |
$run = $true | |
} | |
} | |
Write-Host "" | |
if ($run) { | |
Write-Host "Operation finished successfully." | |
} else { | |
Write-Host "FAILED: update not found" | |
exit 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment