【发布时间】:2016-09-03 01:23:54
【问题描述】:
我的目标是编写一个运行 New-AzureRmResourceGroup 和 New-AzureRmResourceGroupDeployment 的 Powershell 脚本,以便根据 ARM .json 模板文件配置资源组。所述资源组包括虚拟机、虚拟网络、网络安全组、公共IP地址、附加到虚拟机的网络接口和两个存储帐户。之后,我希望继续执行相同的脚本并将特定程序安装程序复制到该资源组中的虚拟机并自动运行该安装程序,而无需进一步的用户交互。但是,我似乎无法开始与虚拟机的远程 Powershell 会话。我运行命令:
$sess = New-PSSession -ComputerName **.***.**.*** -Port XXXX -Credential $cred
*s 是虚拟机的 IP 地址; XXXX 是根据与虚拟机所在的虚拟网络关联的网络安全组为 RDP 开放的端口; $cred 包含虚拟机上管理员用户的凭据。
命令总是返回错误:
New-PSSession : [**.***.**.***] Connecting to remote server **.***.**.*** failed with the following error message :
The client cannot connect to the destination specified in the request. Verify that the service on the destination is
running and is accepting requests. Consult the logs and documentation for the WS-Management service running on the
destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the
destination to analyze and configure the WinRM service: "winrm quickconfig". For more information, see the
about_Remote_Troubleshooting Help topic.
请注意,我确实确保将虚拟机的 IP 地址添加到本地计算机上的受信任主机列表中。 (在我这样做之前,我收到一条不同的错误消息。)另外,如果我在 Azure 门户中单击其连接按钮,然后单击 .rdp,我能够连接到虚拟机下载的文件。此远程会话使用与我在 Powershell 中尝试但未能设置的相同的 IP 地址、端口和凭据。这是我不明白的。
为什么会这样?我需要做一些额外的工作来准备 VM 以接受远程 Powershell 会话吗?有什么方法可以在 ARM 模板中配置它,以便 VM 从一开始就准备好接受它们? (如果我需要在 VM 上运行一些命令来设置 Powershell 远程处理会很困难,因为由于这个问题,我无法远程运行 Powershell 来运行它们。也许我可以将它们作为自定义脚本扩展运行?)
最后说明:此 VM 是“新”样式,而不是“经典”样式。我知道有很多关于“经典”风格的 Azure VM 的文档,但这不是我正在使用的。此外,即使按照错误提示在 VM 上运行 winrm quickconfig,并向本地用户远程启用管理权限,我在运行 New-PSSession 时也会遇到同样的错误。
【问题讨论】:
标签: powershell azure virtual-machine remote-desktop