【发布时间】:2017-10-19 21:19:07
【问题描述】:
我正在尝试编写一个用于卸载更新的 powershell 脚本。
我的问题是脚本在启动脚本时没有运行wusa.exe。
function Uninstall-Hotfix () {
[string]$parameters = "KB4041691"
[string]$KBs = @()
if ($parameters.Contains(":")) {
[object]$arguments = $parameters.Split(":")
foreach ($argument in $arguments) {
$argument.Replace("KB", "")
$KBs.add($argument)
for ($i = 0; $i -lt $KBs.length; $i++) {
Cmd /c wusa.exe /uninstall /KB:$KBs[$i] /quiet /norestart
Do {
Start-Sleep -Seconds 3
}
while (Wait-Process | Where-Object {$_.name -eq "wusa"})
If (Get-Hotfix -Id $KBs[$i] -ErrorAction SilentlyContinue) {
Write-Host "KB $KBs[$i] Fehlerhaft"
}
Else {
Write-Host "KB $KBs[$i] Erfolgreich deinstalliert"
}
}
}
}
Else {
$parameter = $parameters.Replace("KB", "")
$parameter
cmd /c wusa.exe /uninstall /KB:$parameter /quiet /norestart
Do {
Start-Sleep -Seconds 3
}
while (Wait-Process | Where-Object {$_.name -eq "wusa.exe"})
}
}
Uninstall-Hotfix
【问题讨论】:
-
cmd 不是命令,请阅读错误消息。使用Start-process或直接调用wusa.exe
-
试试
& wusa.exe /uninstall /KB:$parameter /quiet /norestart -
@guiwhatsthat:Powershell 没有显示错误,我看到其他脚本也使用“cmd”命令...
-
@JamesC.: 这也不起作用 :( ...我在事件查看器中看到他在应用程序中记录了语法错误,因为他无法读取 kb 编号...现在他没有记录错误,但它仍然没有运行或卸载更新......