【问题标题】:Installing .msu patch file with wusa.exe is not working with invoke-command使用 wusa.exe 安装 .msu 补丁文件不适用于调用命令
【发布时间】:2016-06-15 12:05:23
【问题描述】:

我正在尝试使用Invoke-command 将带有wusa.exe 的Windows 补丁更新(.msu 补丁文件)安装到远程机器上。但它会抛出返回码为 5 的错误。

在不使用start-process 或不提取和安装.cab 文件的情况下,还有其他方法吗?

【问题讨论】:

    标签: powershell-3.0 patch powershell-remoting invoke-command


    【解决方案1】:

    Windows 更新不允许您通过 Powershell 远程会话执行安装,因为它不允许任何远程身份验证令牌。

    这是一个类似的问题: https://serverfault.com/questions/559287/what-does-wusa-exe-return-code-5-mean

    对上述问题的推荐答案是使用 PSRemoting 在机器上创建计划任务。

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题,所以我编写了一个函数来利用计划任务。只需要几个参数。

      我不乐意以纯文本形式传递管理员凭据,但是,某些更新需要这些凭据才能无头运行计划任务。另外,我想在多个临时虚拟机上使用它,所以一组编码的凭据对我来说不起作用。

      哦,睡眠可能不需要,但我想确保它不会运行得太快并捕获不正确的条件。

      tempdir 变量是您的可执行文件所在的工作目录。任务调度程序要求您位于可执行文件的工作目录中,因为它会将工作目录的前缀添加到文件路径中,即使您指定了完整的文件路径.

      #scheduled task wrapper for installing files which normally fail due to 
      #windows restrictions on invoke-command
      function Use-TaskWrapperInstaller {
          param(
              [string]$ffile,
              [string]$farguments,
              [string]$ftaskname,
              [string]$ftempDir,
              [string]$fadmin,
              [string]$fpassword
          )
          Invoke-Command -Session $Global:s -ScriptBlock {
              $action=$(New-ScheduledTaskAction -Execute "$Using:ftempDir\$Using:ffile" -Argument $Using:farguments)
              $principal=$(New-ScheduledTaskPrincipal -GroupId "BUILTIN\Administrators" -RunLevel Highest)
              $settings=$(New-ScheduledTaskSettingsSet)
              $task=(New-ScheduledTask -Action $action -Principal $principal -Settings $settings)
              Set-Location "$Using:ftempDir"
              if ($(Get-ScheduledTask -TaskName "$Using:ftaskname" -ErrorAction SilentlyContinue).State -eq "Ready") {
                          Unregister-ScheduledTask -TaskName "$Using:ftaskname" -Confirm:$false
                      }
              Register-ScheduledTask -TaskName "$Using:ftaskname" -InputObject $task -User "$Using:fadmin" -Password "$Using:fpassword" -ErrorAction SilentlyContinue -Force
              Start-Sleep -Seconds "2"
              Write-Host "Starting installation task: $Using:ftaskname"
              Start-ScheduledTask -TaskName "$Using:ftaskname"
              Start-Sleep -Seconds "2"
              Do {
                  Start-Sleep -Seconds "1"
              } Until ($(Get-ScheduledTask -TaskName "$Using:ftaskname" -ErrorAction SilentlyContinue).State -match "Ready")
              Write-Host "Installation of $Using:ftaskname using Task Wrapper complete."
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2018-05-16
        • 1970-01-01
        • 2011-06-14
        • 2015-05-21
        • 1970-01-01
        • 2011-11-29
        • 1970-01-01
        • 2011-06-13
        • 1970-01-01
        相关资源
        最近更新 更多