Powershell 到 EC2 实例 - 在 EC2 实例上安装可执行文件

Pri*_*nce 3 powershell amazon-ec2

我是亚马逊服务器的新手。我最近创建了一个 EC2 Windows2008 R2 实例,并尝试使用 powershell ALONE 从我的系统连接到该实例

我不想在连接、将文件从本地传输到 EC2 或在 EC2 实例中安装文件时使用 Amazon API。

我想通过使用 POWERSHELL 来完成所有这些。

我能够将文件从本地连接和传输到 EC2,有人可以建议/帮助在此 EC2 实例上安装可执行文件。

对此事的任何帮助深表感谢!提前谢谢

小智 5

如果您可以从命令行安装可执行文件(“静默安装”),那么 powershell 远程处理是最佳选择。默认情况下,它在 Amazon Windows 映像上处于启用状态,因此您无需执行任何操作,只需启动机器并获取密码即可。

这里有设置远程的说明:https : //stackoverflow.com/a/13284313/1335661

最重要的是,您可以使用以下脚本来执行远程命令(取自:https : //github.com/CloudifySource/cloudify/blob/master/esc/src/main/resources/clouds/ec2-win/上传/引导客户端.ps1):

param ([string]$target, [string]$username, [string]$password, [string]$command)

$ErrorActionPreference="Stop"

# Set up the password
$securePassword = ConvertTo-SecureString -AsPlainText -Force $password
$cred = New-Object System.Management.Automation.PSCredential $username, $securePassword

Write-Host "Connecting to management service of $target"
Connect-WSMan -Credential $cred $target 

set-item WSMan:\$target\Client\TrustedHosts -Value * -Force
set-item WSMan:\$target\Shell\MaxMemoryPerShellMB -Value 0 -Force

Write-Host Invoking command on Remote host $target
Invoke-Command -ComputerName $target -Credential $cred  -ScriptBlock {  
    Invoke-Expression $args[0]
} -ArgumentList $command
Write-Host "Command finished"
Run Code Online (Sandbox Code Playgroud)

您可以使用以下命令从您自己的脚本运行此命令:

powershell.exe -inputformat none -File PATH_TO_SCRIPT -target TARGET_IP -password PASSWORD -username USERNAME -command COMMAND_TO_EXECUTE
Run Code Online (Sandbox Code Playgroud)