【问题标题】:Install Offline Windows Updates(.msu) to remote servers将脱机 Windows 更新 (.msu) 安装到远程服务器
【发布时间】:2021-11-07 01:11:47
【问题描述】:

我正在尝试编写一个脚本,以便在一些连接在离线域中的远程服务器上远程安装一些 Windows 更新。

我已经尝试过常规的 PS Remoting,经过一些研究,我认为我正在尝试做的事情不受 Microsoft 的支持。检查我的事件日志时,我遇到了一堆这样的错误。

编辑

我想补充一点,我已尝试从本地计算机运行 .\Install2012R2.ps1 脚本,修改为在其中包含 Invoke-Command 并让它运行原始 Install2012R2.ps1 的更新部分,我会得到相同的结果错误。

我希望通过将脚本放置在每台服务器上,它会更喜欢它。

结束编辑

Windows update  could not be installed because of error 2147942405 "Access is denied."
(Command line: ""C:\Windows\System32\wusa.exe" "C:\Updates\windows8.1-kb4556853-x64.msu" /quiet /norestart")

我尝试以服务器上管理员帐户的凭据运行Invoke-Command,但我一直没有运气,并且正在寻找一些建议,如果有人之前可能尝试过/做过此操作。

$Servers = @("V101-Test1","V101-Test2")
$Username = 'admin'
$Password = 'Password'#not actual password
$pass = ConvertTo-SecureString -AsPlainText $Password -Force
$Cred = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$pass

Get-PSSession | Remove-PSSession
New-PSSession -ComputerName $Servers

foreach($Server in $Servers){
    Get-ChildItem -Path C:\Source\Temp -Recurse | Copy-Item -Destination "\\$Server\c$\Updates\" -Force
}

Invoke-Command $Servers -Credential $Cred -ScriptBlock{

& "C:\Updates\Install2012R2.ps1"

}

编辑 2

这是Install2012R2.ps1脚本的实际安装代码

$updatedir= "./"
$files = Get-ChildItem $updatedir -Recurse


$msus = $files | ? {$_.extension -eq ".msu"}
$exes = $files | ? {$_.extension -eq ".exe"}

foreach ($file in $msus){
    $KBCtr++
    $fullname = $file.fullname
        
    # Need to wrap in quotes as folder path may contain space   
    $fullname = "`"" + $fullname + "`""
    $KBN = $fullname.split('-')[1]

# Need to wrap in quotes as folder path may contain space   
$fullname = "`"" + $fullname + "`""
    # Specify the command line parameters for wusa.exe
        $parameters = $fullname + " /quiet /norestart"

        # Start services and pass in the parameters
    $install = [System.Diagnostics.Process]::Start( "wusa",$parameters )
    $install.WaitForExit()
}

【问题讨论】:

  • Install2012R2.ps1 是否连接到任何远程服务器?这将包括一个像\\server.domain.tld\ShareName$\somefile.ext这样的UNC路径上的东西。
  • 不,它没有,它所做的只是收集所有 .msus 并尝试安装它们。 编辑我在最后的原帖中添加了Install2012R2.ps1的实际安装信息
  • 它从哪里收集 MSU?我没有看到你在运行调用命令之前复制它们,所以我认为它需要从某个地方拉它们?还是他们已经在C:\Updates下的目标服务器上暂存?
  • $updatedDir 的价值从何而来? 什么$updatedDir的值是什么?
  • 我在后半部分添加了$UpdatedDir 变量。 Install2012R2.ps1 脚本驻留在服务器上,MSU 文件位于 C:\Updates

标签: windows powershell windows-update


【解决方案1】:

我不确定为什么 wusa.exe 在此处因访问被拒绝而失败,但您可以尝试以下 PowerShell 原生方法。如果不出意外,它应该通过捕获的错误信息为您提供更清晰的指示,说明根本问题是什么:

Add-WindowsPackage -Path C:\Updates\OurHeroicUpdate.msu -Online -PreventPending -NoRestart
  • -Pathmsu 文件的路径
  • -Online 告诉 Add-WindowsPackage 修改 Windows 的当前“挂载映像”(运行版本)(而不是您也可以将其应用到的脱机磁盘映像)
  • -PreventPending 阻止安装 msu 如果已经有待处理的更改,例如需要重新启动以进行更新。

Add-WindowsPackage 是 Windows PowerShell 下可用的DISM 模块的一部分,并且在功能上等同于dism /packagepath:"cabfile",尽管它可以采用msu,其中dism.exe 只允许cab

【讨论】:

    猜你喜欢
    • 2012-06-05
    • 1970-01-01
    • 1970-01-01
    • 2010-09-08
    • 1970-01-01
    • 2018-08-22
    • 2011-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多