使用wusa.exe安装.msu补丁文件不能与invoke-command一起使用

问题描述 投票:0回答:2

我正在尝试使用.msu将带有wusa.exe的Windows补丁更新(Invoke-command补丁文件)安装到远程计算机上。但是返回代码5会引发错误。

有没有其他方法可以使用start-process或不提取和安装.cab文件?

powershell-v3.0 patch powershell-remoting invoke-command
2个回答
0
投票

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

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

针对上述问题的建议答案是使用PSRemoting在计算机上创建计划任务。


0
投票

我有同样的问题所以我写了一个函数来利用计划任务。只需要一些论点。

我很高兴以纯文本形式传递管理员信誉,但是,有些更新需要这些才能运行预定的任务无头。此外,我想在多个短暂的虚拟机上使用它,因此一组编码的信用卡对我来说不起作用。

哦,可能不需要睡眠,但我想确保它没有跑得太快并且捕捉到不正确的情况。

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."
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.