-
Notifications
You must be signed in to change notification settings - Fork 16
/
Remove Windows Updates.ps1
36 lines (32 loc) · 1.29 KB
/
Remove Windows Updates.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#Remove Windows Updates
#Load VB-based dialog window
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null
$ErrorActionPreference = "SilentlyContinue"
$HotfixID = [Microsoft.VisualBasic.Interaction]::InputBox("What is the KB number of the update to remove?", "Update KB Number")
$query = Get-ADComputer -Filter {Enabled -eq $true} | Sort Name
$computers = $query.Name
foreach ($computer in $computers) {
if(Test-Connection $computer -Count 1 -Quiet) {
$GetOSVer = (Get-WMIObject -ComputerName $computer -class Win32_OperatingSystem).Version
$Hotfix = Get-Hotfix -Id KB$HotfixID -ComputerName $computer
if ($Hotfix) {
Write-Host -Foreground Yellow -Background Black "Removing hotfix KB$HotfixID on $computer"
if ($GetOSVer -like "5.1*" -or $GetOSVer -like "5.2*") {
Invoke-Command -ComputerName $computer -ScriptBlock {
C:\Windows\`$NtUninstallKB$using:HotfixID`$\spuninst\spuninst.exe /quiet /norestart
}
}
else {
Invoke-Command -ComputerName $computer -ScriptBlock {
cmd.exe /c wusa.exe /uninstall /kb:$using:HotfixID /quiet /norestart
}
}
}
else {
Write-Host -Foreground Yellow -Background Black "Hotfix not installed on $computer"
}
}
else {
Write-Host -Foreground Yellow -Background Black "Can't ping $computer"
}
}