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

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

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

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

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

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

如果你可以从命令行安装你的可执行文件('silent install'),那么PowerShell远程是最好的select。 它在默认情况下在亚马逊Windows图像上,所以你不需要做任何事情,然后启动机器并获取密码。

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

底线是您可以使用以下脚本来执行远程命令(摘自: https : //github.com/CloudifySource/cloudify/blob/master/esc/src/main/resources/clouds/ec2-win/上传/ bootstrap-client.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" 

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

 powershell.exe -inputformat none -File PATH_TO_SCRIPT -target TARGET_IP -password PASSWORD -username USERNAME -command COMMAND_TO_EXECUTE 

除非你在PowerShell远程处理方面很精明,否则我build议只打开RDP(TCP 3389)和Remote Desktoping(在连接本地驱动器的客户端框中)并上传文件。 之后,您可以尝试使用服务器上的PowerShell命令Enable-PSRemoting,打开5986(SSL)的防火墙并尝试远程访问。

不知道你可以通过PowerShell远程shell本地“隧道”传输文件,虽然似乎有一个第三方模块 。

我假设你正在谈论在服务器上安装软件,而不必login。

一种select是在你的服务器上安装https://github.com/bwight/CloudInit.NET并保存AMI。 然后,你可以编写一个powershell脚本,在本地服务器上运行,并安装/下载任何你需要的服务器。

使用AMI创build新服务器时,只需将文件的内容作为用户数据或用户数据文件。 当服务器启动时,CloudInit.NET服务将下载并执行脚本,而无需login到服务器。