简体   繁体   English

无法安装 Microsoft 更新(修补程序)-通过 PowerShell 脚本的 msu

[英]Not able to install Microsoft update (hotfix) - msu through PowerShell script

I am trying to install MSU through below PowerShell script, but its not getting installed.我正在尝试通过下面的 PowerShell 脚本安装 MSU,但它没有安装。 I am not aware of PowerShell scripting.我不知道 PowerShell 脚本。 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"

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.为了能够将参数传递给通过Start-Process ,(可能在位置上隐含的) -FilePath参数必须是真正的可执行文件,而不仅仅是.msu文件的文档

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):因此,您必须将.msu文件已注册以显式处理的可执行文件传递给-FilePath ,即wusa.exe (注意-ArgumentList参数末尾的/quiet /norestart ):

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.为了等待安装完成,添加-Wait开关。

  • 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.要额外检查进程的退出代码以确定安装是否成功,请添加-PassThru开关,将生成的进程信息对象捕获到变量中,然后检查其.ExitCode属性。

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:但是,有一个技巧可以简化上述操作:将wusa.exe调用传递给Write-Output ,这会强制它同步执行(作为 GUI 子系统应用程序, 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.'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM