powershell - 如何从资源管理器 PSSession VM?

标签 powershell azure azure-resource-manager azure-automation runbook

我在资源管理器中有虚拟机,我想从这些虚拟机的 Runbook 中执行远程 PowerShell 脚本编写。我已经知道如何在经典虚拟机中进行操作并成功使用。

现在,在使用 Azure 资源管理器创建的 Azure VM 上默认启用证书的 SSL 远程 PowerShell 是否已启用?如何与 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.

注意:我在 Azure 自动化中使用 Powershell Runbook 运行此程序。 并尝试了建议的答案 here

最佳答案

您需要将证书放入 Azure Key Vault(加上一些其他步骤)才能启用 WinRM 到 ARM VM。然后您需要执行与 Connect-AzureVM 中相同的操作Runbook,但使用此证书而不是 Azure 经典 VM 的证书来建立主机之间的信任。

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

关于powershell - 如何从资源管理器 PSSession VM?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36421521/

相关文章:

azure - 期望以 '/subscriptions/{subscriptionId}' 开头的完全限定资源 ID

Azure Bicep - 部署失败(冲突)对此资源或依赖资源的另一项操作正在进行中 (AnotherOperationInProgress)

azure - Bicep isHnsEnabled 无法更新

powershell - Powershell-错误检查以查找和替换(ForEach对象)

PowerShell 删除项目不等待

regex - 如何使用 -Filter (使用正则表达式)?

python - 如何返回 API 响应并同时使程序失败?

excel - PowerShell + Excel - $workbook.save() 挂断了我的电话

linux - Azure 批处理 - 在 Linux VM 上从命令行运行多个命令

azure - 如何使用 Azure AD 登录我的 .NET API?