執行在Amazon EC2實例遠程PowerShell腳本我有一個Amazon EC2實例。從我的本地計算機
我的本地工作站上使用PowerShell,我希望能夠遠程連接到我的Amazon EC2實例,並執行一些命令。
我發現有很多網上的文章,但沒有工作或我誤解了他們(可能是後者)。
一些我想是
Managing Windows EC2 Instances remotely with Powershell
Administering EC2 instance with Windows Powershell
Enabling- PSRemoting
How to Run PowerShell Commands on Remote Computers
我的理解是,我需要:
Amazon EC2 Dashboard > Network & Security > Security Groups > Add port 5985
//Local & EC2 PowerShell(Administrator)
enable-psremoting -force
//Local PowerShell(Administrator)
set-item wsman:\localhost\Client\TrustedHosts -value "*" -force
$password = convertto-securestring -asplaintext -force -string myPassword
$credential = new-object -typename system.management.automation.pscredential -argumentlist "myUsername", $password
$session = new-pssession ec2-00-00-00-000.compute-1.amazonaws.com -credential $credential
enter-pssession $session
但我得到這個錯誤
new-pssession : [ec2-00-00-00-000.compute-1.amazonaws.com] Connecting to remote server
ec2-00-00-00-000.compute-1.amazonaws.com failed with the following error message : WinRM cannot complete the
operation. Verify that the specified computer name is valid, that the computer is accessible over the network, and
that a firewall exception for the WinRM service is enabled and allows access from this computer. By default, the WinRM
firewall exception for public profiles limits access to remote computers within the same local subnet. For more
information, see the about_Remote_Troubleshooting Help topic.
At line:1 char:12
+ $session = new-pssession ec2-00-00-00-000.compute-1.amazonaws.com -credential $c ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotin
gTransportException
+ FullyQualifiedErrorId : WinRMOperationTimeout,PSSessionOpenFailed
您是否允許端口5985/5986本地?運行'winrm quickconfig'確認兩臺機器配置正確(儘管我認爲enable-psremoting應該已經處理了這一步)。 –
@HyperAnthony我運行了'winrm quickconfig' - >我得到了'WinRM服務已經在這臺機器上運行了。 WinRM已經在此計算機上進行遠程管理。# –
什麼是您的亞馬遜服務器的操作系統? – MDMoore313