1

我在资源管理器中有虚拟机,我想从这些虚拟机的Runbook中执行远程PowerShell脚本。我已经知道如何在经典的虚拟机中做到这一点,并成功地使用它。如何从资源管理器PSSession VM?

现在,基于SSL的远程PowerShell是否具有默认情况下在使用Azure资源管理器创建的Azure虚拟机上启用的证书?我如何连接到Enter-PSSession或Invoke-Command?

我试过这段代码没有成功。

Enter-PSSession -ComputerName <public-IP> -Credential $cred -SessionOption (New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck) 

而且我得到这个错误

Enter-PSSession : Connecting to remote server <public-IP> failed with the following error message : The WinRM client 
cannot process the request. If the authentication scheme is different from Kerberos, or if the client computer is not 
joined to a domain, then HTTPS transport must be used or the destination machine must be added to the TrustedHosts 
configuration setting. Use winrm.cmd to configure TrustedHosts. Note that computers in the TrustedHosts list might not 
be authenticated. You can get more information about that by running the following command: winrm help config. For more 
information, see the about_Remote_Troubleshooting Help topic. 

注意:我使用PowerShell运行手册在Azure中运行自动化此。 并尝试了建议的答案here

+0

使用HTTPS配置VM远程PowerShell,然后重试。你应该有'Transport = HTTPS'和'Port = 5986'。 –

+0

@JackZeng已经完成了='(但仍然没有成功的远程处理 –

回答

1

您需要在Azure密钥保管库中放置证书(以及其他一些步骤)以启用WinRM到ARM VM。然后,您需要执行与Connect-AzureVM Runbook中相同的操作,但使用此证书而不是Azure Classic VM的证书来设置主机之间的信任关系。

有关所需步骤的更多详细信息,请参见this threadThis也可能有用。

+0

我仍然无法连接='(我在这里也跟着步骤 - > https://blogs.technet.microsoft.com/uktechnet/2016/02/11 /配置-winrm-over-https-enable-powershell-remoting/ –

+0

我试图在我的本地计算机中使用Powershell进行PSSession,它工作正常我只是把远程服务器的public_ip设置为trustedhost。我怎么会在azure门户中这样做?你有什么想法吗? –

+0

我不认为Enter-PSSession可以用于像Azure Automation运行的那些无人值守的会话。一旦代码进入会话,没有用户在场接下来要运行的命令怎么样Invoke-Command? – Joe