无法通过PowerShell脚本安装Microsoft Update(Hotfix)-MSU

发布于 2025-02-04 00:38:08 字数 238 浏览 1 评论 0 原文

我正在尝试通过以下PowerShell脚本安装MSU,但没有安装。我不知道Powershell脚本。请有人给我最佳修改此脚本的方法。我期待听到。

Start-Process "C:\Installer\windows10.0-kb4520062-x64_9f2a827f11f945d19bd26de6f113f611a38bb8a1.msu" -ArgumentList "/quiet /norestart"

I am trying to install MSU through below PowerShell script, but its not getting installed. I am not aware of PowerShell scripting. Please someone give me best way to modified this script. I am looking forward to hear.

Start-Process "C:\Installer\windows10.0-kb4520062-x64_9f2a827f11f945d19bd26de6f113f611a38bb8a1.msu" -ArgumentList "/quiet /norestart"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故人如初 2025-02-11 00:38:09

为了能够将参数传递到通过 start-process ,(可能是定位暗示的) -filePath 参数必须是一个true 可执行 /em>,不仅是 document ,这是 .msu 文件的内容。

因此,您必须将 .msu 文件注册以通过显式处理 -filepath ,即 wusa的可执行文件。 exe (注意/quet/norestart -argumentList 参数的结尾处):

Start-Process `
  -FilePath     "$env:SystemRoot\System32\wusa.exe" `
  -ArgumentList 'C:\Installer\windows10.0-kb4520062-x64_9f2a827f11f945d19bd26de6f113f611a38bb8a1.msu /quiet /norestart'

注意:

  • 为了等待安装完成,添加 -Wait Switch。

  • 另外检查该过程的退出代码以确定安装是否成功,请添加 -PassThru Switch,在变量中捕获所得的Process-Info对象,然后检查其 .exitCode 属性。

但是,有一个技巧简化了上述:管道 wusa.exe call to 写入输出,它迫使其同步执行(作为GUI-Subsystem应用程序, wusa.exe 否则会异步运行),还将其退出代码记录在自动 $ $ lastExitCode 变量:

# Note the "| Write-Output" at the end of the line,
# which makes wusa.exe run synchronously and records its process
# exit code in $LASTEXITCODE.
& "$env:SystemRoot\System32\wusa.exe" C:\Installer\windows10.0-kb4520062-x64_9f2a827f11f945d19bd26de6f113f611a38bb8a1.msu /quiet /norestart | Write-Output

if ($LASTEXITCODE -ne 0)
  throw "wusa.exe indicates failure; exit code was: $LASTEXITCODE"
}

'Installation succeeded.'

In order to be able to pass arguments to a process launched via Start-Process, the (possibly positionally implied) -FilePath argument must be a true executable, not just a document, which is what a .msu file is.

Therefore, you must pass the executable that .msu files are registered to be processed by explicitly to -FilePath, which is wusa.exe (note the /quiet /norestart at the end of the -ArgumentList argument):

Start-Process `
  -FilePath     "$env:SystemRoot\System32\wusa.exe" `
  -ArgumentList 'C:\Installer\windows10.0-kb4520062-x64_9f2a827f11f945d19bd26de6f113f611a38bb8a1.msu /quiet /norestart'

Note:

  • In order to wait for the installation to finish, add the -Wait switch.

  • To additionally check the process' exit code in order to determine whether the installation succeeded, add the -PassThru switch, capture the resulting process-info object in a variable, and then check its .ExitCode property.

However, there is a trick that simplifies the above: pipe the wusa.exe call to Write-Output, which forces it to execute synchronously (as a GUI-subsystem application, wusa.exe would otherwise run asynchronously) and also records its exit code in the automatic $LASTEXITCODE variable:

# Note the "| Write-Output" at the end of the line,
# which makes wusa.exe run synchronously and records its process
# exit code in $LASTEXITCODE.
& "$env:SystemRoot\System32\wusa.exe" C:\Installer\windows10.0-kb4520062-x64_9f2a827f11f945d19bd26de6f113f611a38bb8a1.msu /quiet /norestart | Write-Output

if ($LASTEXITCODE -ne 0)
  throw "wusa.exe indicates failure; exit code was: $LASTEXITCODE"
}

'Installation succeeded.'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文