简体   繁体   English

为什么AWS-ConfigureWindowsUpdate SSM运行命令失败?

[英]Why is AWS-ConfigureWindowsUpdate SSM Run Command Failing?

Enabling or Disabling Windows Updates with SSM Run Command 使用SSM Run命令启用或禁用Windows更新
AWS-ConfigureWindowsUpdate AWS配置WindowsUpdate

When running the command, it downloads a PowerShell script to my EC2 at "C:\\ProgramData\\Amazon\\Ec2Config\\Downloads\\aws_psModule\\" with a random name 运行命令时,它将使用随机名称在“ C:\\ ProgramData \\ Amazon \\ Ec2Config \\ Downloads \\ aws_psModule \\”下将PowerShell脚本下载到我的EC2。

When the PowerShell script executes, it downloads "Amazon.ConfigureWindowsUpdate-1.2.zip" to "%Temp%" and then unzips it to "%WinDir%\\System32\\WindowsPowerShell\\v1.0\\Modules" 在执行PowerShell脚本时,它将“ Amazon.ConfigureWindowsUpdate-1.2.zip”下载到“%Temp%”,然后将其解压缩到“%WinDir%\\ System32 \\ WindowsPowerShell \\ v1.0 \\ Modules”

The script looks to be failing at Line 32 with the .CopyHere function where it is unzipping 该脚本似乎在第32行中带有.CopyHere函数的错误位置,该文​​件正在解压缩
Pastebin of Powershell Script: 1b3hh3oy.k51.ps1 Powershell脚本的Pastebin:1b3hh3oy.k51.ps1

(New-Object -Com Shell.Application).namespace($powerShellModuleLocation).CopyHere((New-Object -Com Shell.Application).namespace($tempLocation).Items(), 16)

Output: 输出:

Obtaining instance region from instance metadata. 从实例元数据获取实例区域。
Downloading ConfigureWindowsUpdate PowerShell module from S3. 从S3下载ConfigureWindowsUpdate PowerShell模块。
Verifying SHA 256 of the ConfigureWindowsUpdate PowerShell module zip file. 验证ConfigureWindowsUpdate PowerShell模块zip文件的SHA 256。
ExtractingConfigureWindowsUpdate zip file contents to the Windows PowerShell module folder. 将ConfigureWindowsUpdateWindowsUpdate zip文件内容提取到Windows PowerShell模块文件夹中。
--------------ERROR-------------- C:\\ProgramData\\Amazon\\Ec2Config\\Downloads\\aws_psModule\\1b3hh3oy.k51.ps1 : --------------错误-------------- C:\\ ProgramData \\ Amazon \\ Ec2Config \\ Downloads \\ aws_psModule \\ 1b3hh3oy.k51.ps1:
Exception thrown while downloading ConfigureWindowsUpdate PowerShell module with message: Exception has been thrown by the target of an invocation. 下载带有消息的ConfigureWindowsUpdate PowerShell模块时引发异常调用的目标已引发异常。
At line:1 char:1 + . 在第1行:char:1 +。 'C:\\ProgramData\\Amazon\\Ec2Config\\Downloads\\aws_psModule\\1b3hh3oy.k51.ps1' ; 'C:\\ ProgramData \\ Amazon \\ Ec2Config \\ Downloads \\ aws_psModule \\ 1b3hh3oy.k51.ps1'; ex ... 前...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~ + + CategoryInfo:未指定:(:) [Write-Error],WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,1b3hh3oy.k51.ps1 + FullyQualifiedErrorId:Microsoft.PowerShell.Commands.WriteErrorException,1b3hh3oy.k51.ps1

Other Details: 其他详情:
- I have micro EC2 of Windows Server Core 2012 R2 running -我正在运行Windows Server Core 2012 R2的微型EC2
- I have successfully used AWS-RunPowerShellScript command a few times from AWS Console -我已经从AWS控制台成功几次使用AWS-RunPowerShellScript命令
- I ran AWS-ConfigureWindowsUpdate through the AWS Console and it fails -我通过AWS控制台运行AWS-ConfigureWindowsUpdate,但失败
- I remote connected to server and ran the powershell script with administrator privileges and get same error -我远程连接到服务器,并以管理员权限运行Powershell脚本,并得到相同的错误

You are correct, the exception is occurring on the call out to the Shell namespace for extracting the cmdlet payload. 您是正确的,在调用Shell命名空间以提取cmdlet有效负载时发生了异常。 The COM namespace for Shell access is not included in the Core release so the ConfigureWindowsUpdate script fails when extracting the cmdlet. Core发行版中未包含用于Shell访问的COM名称空间,因此在提取cmdlet时,ConfigureWindowsUpdate脚本失败。

Currently there is a workaround available for Windows Server Core AMIs and a more complete fix is currently being investigated. 当前,Windows Server Core AMI提供了一种解决方法,并且正在研究更完整的修复程序。 The workaround involves creating a custom ConfigureWindowsUpdate document with a tweak to fix the extraction process. 解决方法是创建带有调整的自定义ConfigureWindowsUpdate文档,以修复提取过程。

Below is a function that would replace the call to 下面是一个函数,它将替换对

(New-Object -Com Shell.Application).namespace($powerShellModuleLocation).CopyHere((New-Object -Com Shell.Application).namespace($tempLocation).Items(), 16)

function ExtractZipCoreOs($zipFilePath, $destPath) {
    try
    {
        [System.Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem") | Out-Null

        $zip = [System.IO.Compression.ZipFile]::OpenRead($zipFilePath)

        foreach ($item in $zip.Entries) {
            $extractedPath = Join-Path $destPath $item.FullName

            if ($item.Length -eq 0) {
                if ((Test-Path $extractedPath) -eq 0) {
                    mkdir $extractedPath | Out-Null
                }
            } else {
                $fileParent = Split-Path $extractedPath

                if ((Test-Path $fileParent) -eq 0) {
                    mkdir $fileParent | Out-Null
                }

                [System.IO.Compression.ZipFileExtensions]::ExtractToFile($item,(Join-Path -Path $powerShellModuleLocation -ChildPath $item.FullName), $true)
            }
        }
    } 
    catch
    {
        throw "Error encountered when extracting ConfigureWindowsUpdate zip file.`n$($_.Exception.Message)"
    }
    finally
    {
        $zip.Dispose()
    }
}

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

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