sm代理程序.description下载代理程序,安装它,必须作为管理员.PARAMETER代理程序托管程序运行系统安装后还将设置SSM代理配置,以便在注册阶段使用输入应写入 : 格式化华体会体育推荐abjective_service_service_service_service_serv"JOB_RETRIEVE_FAILURE"=2!"NO_JOB_FOUND"=3!OS_UNSPORED=4;}写输出检查vm注册令牌.元元-十元$num++/$JWT_token=&C:\productfileVMware工具.exe'info-getinfo.Megroi华体会体育推荐" + "Confirm if the customer vCenter is configured for population of the token with the Product team." ) exit 10 } $AgentDir = "$Env:ProgramFiles\Amazon\SSM" function Find-Instance-Id { if(Test-Path -Path "$AgentDir\ssm-cli.exe" -PathType Leaf) { $output = & "$AgentDir\ssm-cli.exe" get-instance-information | ConvertFrom-Json $managed_instance_id = $output.psobject.properties["instance-id"].value if($managed_instance_id.StartsWith("mi-")) { return 0 } } return 1 } $has_instance_id = Find-Instance-Id if($has_instance_id -eq 0) { Write-Output "Instance Id already exists, do not re-run the activation." exit 0 } function Send-Error($error_code, $JWT_TOKEN) { $Params = @{ Uri = "$platform_services_base_url/instance/error/$error_code" Method = 'POST' Headers = @{'X-Auth-Token' = $JWT_TOKEN} UseBasicParsing = $true } if ($Proxy) {$Params['Proxy'] = $Proxy} Invoke-WebRequest @Params } if ($PSVersionTable.PSVersion.Major -lt 3) { Write-Output "PowerShell version unsupported." exit 10 } $supported = @("2012", "2016", "2019", "2022") $isServer = (Get-CimInstance Win32_OperatingSystem | Select-Object -expand ProductType) -eq 3 $isDomainController = (Get-CimInstance Win32_OperatingSystem | Select-Object -expand ProductType) -eq 2 $osName = Get-CimInstance Win32_OperatingSystem | Select-Object -expand Caption $isVersionSupported = $null -ne ($supported | Where-Object { $osName -match $_ }) $isSupported = ([Environment]::Is64BitOperatingSystem) -and ($isServer -or $isDomainController) -and $isVersionSupported if(-Not $isSupported) { Write-Output "Operating System version unsupported." Send-Error $error_codes.OS_UNSUPPORTED $JWT_TOKEN exit 10 } #$addon_access_url = "https://add-ons.api.manage.rackspace.com/v1.0/instance/activate" try { $Params = @{ Uri = $addon_access_url Method = 'POST' Headers = @{'X-Auth-Token' = $JWT_TOKEN!'Content-Type' = 'application/json'} UseBasicParsing = $true } if ($Proxy) {$Params['Proxy'] = $Proxy} $access_job_response = Invoke-WebRequest @Params } catch { Write-Output "Unable to create activation for ssm." Send-Error $error_codes.UNABLE_TO_ACTIVATE $JWT_TOKEN exit 11 } $job_location = $access_job_response.headers.Location $status = "RUNNING" $activation = $null DO { Start-Sleep -s 10 try { $Params = @{ Uri = $job_location Method = 'GET' Headers = @{'X-Auth-Token' = $JWT_TOKEN} UseBasicParsing = $true } if ($Proxy) {$Params['Proxy'] = $Proxy} $job_status_response = Invoke-WebRequest @Params } catch { Write-Output "Failed to get job status while getting activation for SSM" Send-Error $error_codes.JOB_RETRIEVE_FAILURE $JWT_TOKEN exit 11 } $job_json_response = ConvertFrom-Json $job_status_response.Content $cnt = $job_json_response.data.currentItemCount if ($cnt -ne 1) { Write-Output "Unexpected response from job status while activating SSM." Send-Error $error_codes.NO_JOB_FOUND $JWT_TOKEN exit 11 } $status = $job_json_response.data.items[0].status $activation = $job_json_response.data.items[0].message } While ($status -eq "RUNNING") if ($status -ne "SUCCEEDED") { Write-Output "Failed to create an activation for SSM" Send-Error $error_codes.UNABLE_TO_ACTIVATE $JWT_TOKEN exit 11 } $activationcode = $activation.activation_code $activationid = $activation.activation_id $region = $activation.region $DownloadDir = $env:TEMP + "\ssm" New-Item -ItemType Directory -Path $DownloadDir -Force | Out-Null # download the SSM agent installer $Params = @{ Uri = "https://s3.$region.amazonaws.com/amazon-ssm-$region/latest/windows_amd64/AmazonSSMAgentSetup.exe" OutFile = ($DownloadDir + "\AmazonSSMAgentSetup.exe") } if ($Proxy) {$Params['Proxy'] = $Proxy} Invoke-WebRequest @Params # uninstall previous version, if any Start-Process "$DownloadDir\AmazonSSMAgentSetup.exe" -ArgumentList @("/norestart", "/uninstall", "/q", "/log", "uninstall.log") -Wait # install and register the agent if ($Proxy) { Start-Process "$DownloadDir\AmazonSSMAgentSetup.exe" -ArgumentList @("/norestart", "/q", "/log", "install.log") -Wait $service_key = "HKLM:\SYSTEM\CurrentControlSet\Services\AmazonSSMAgent" $key_info = (Get-Item -Path $service_key).GetValue("Environment") $proxy_variables = @("http_proxy=$Proxy", "https_proxy=$Proxy") if ($null -eq $key_info) { New-ItemProperty -Path $service_key -Name Environment -Value $proxy_variables -PropertyType MultiString -Force } else { Set-ItemProperty -Path $service_key -Name Environment -Value $proxy_variables } Start-Process "$AgentDir\amazon-ssm-agent.exe" -ArgumentList @("-register", "-code", $activationcode, "-id", $activationid, "-region", $region) -Wait } else { Start-Process "$DownloadDir\AmazonSSMAgentSetup.exe" -ArgumentList @("/norestart", "/q", "/log", "install.log", "CODE=$activationcode", "ID=$activationid", "REGION=$region") -Wait } Get-Content ($env:ProgramData + "\Amazon\SSM\InstanceData\registration") Get-Service -Name "AmazonSSMAgent" $output = & "$AgentDir\ssm-cli.exe" get-instance-information | ConvertFrom-Json $managed_instance_id = $output.psobject.properties["instance-id"].value Write-Output "ssm_instance_id=$managed_instance_id"
Baidu
map