删除已安装的Windows修补程序

时间:2018-03-02 11:17:07

标签: powershell powershell-v5.0

我正在尝试编写一个小脚本来删除Win 10计算机上所有已安装的修补程序。由于我没有找到能够做到这一点的模块,我使用了Start-Process wusa.exe -ArgumentList

虽然文本文件确实只包含ArgumentList中变量所需的纯数字(否则它将是KBKB1234565),但没有任何反应。

我不确定如何看到wusa实际上做了什么,所以我坚持使用不起作用的东西,但我不知道为什么。

Powershell 5.1.16299.98,ExecutionPolicy未签名,在本地AdminAccount上提升shell。

#get ONLY the KB number and write in file
$KB = Get-Hotfix | Select HotfixID 
$KB -replace ".*B" -replace "}" | Out-File c:\temp\temp.txt -append
$KB = Get-Content "C:\temp\temp.txt"

#remove all KBs in said file
ForEach ($Hotfix in $KB)
{
    Write-Host "Uninstalling KB$Hotfix"
    Start-Process wusa.exe -ArgumentList "/uninstall /KB:$Hotfix /quiet /norestart" -Wait 
}

编辑:EventViewer sais(已翻译):

Due to an error, the Windows-Update could not be uninstalled. 
Error: 2147942487 "Wrong Parameter." 
(CommandLine:""C:\WINDOWS\system32\wusa.exe" /uninstall /KB:4054517 /quiet /norestart ")

1 个答案:

答案 0 :(得分:1)

这是一个简单的单行程,可以做同样的事情。

(get-hotfix).hotfixid.replace("KB","") | % {& wusa.exe /uninstall /KB:$_ /quiet /norestart}

就你的问题而言,你做得对。从一些快速谷歌搜索,你可能有一个损坏的修补程序,但不太可能。有趣的是,当我尝试使用伪造的KB代码卸载一个时,它会给我一个不同的错误代码。

对于该错误,请尝试仅卸载引发错误的特定修补程序,并报告事件日志所说的内容/ WUSA所说的内容。

即。 (没有安静,所以你可以看到它的内容)

wusa.exe /uninstall /KB:4054517 /norestart