远程 PowerShell 到 AzureRM 虚拟机
Remote PowerShell to AzureRM Virtual Machines
我已成功将多个 Azure 虚拟机部署到 Azure 资源组。也就是说,我正在使用新的 Azure Resource Manager 部署模型从 JSON 模板部署虚拟机和相关资源。
我的问题是如何从我的笔记本电脑针对这些 VM 执行远程 PowerShell 脚本。我已经梳理了很多文章 - 但它们都展示了如何使用 Azure 中的经典虚拟机来实现。这个我已经知道并成功使用了。
现在,在使用 Azure 资源管理器创建的 Azure 虚拟机上,是否默认启用证书远程 PowerShell over SSL?如何连接 Enter-PSSession 或 Invoke-Command?
这适用于现有机器:通过 NIC 设置确保您的 VM 具有 public IP。接下来,如果您要使用笔记本电脑,请确保您的防火墙对 public 流量开放。这可以通过一个简单的 netsh 命令来完成:
netsh advfirewall firewall add rule name="WinRM HTTP" dir=in action=allow protocol=TCP localport=5985 profile=public
打开 public IP 和防火墙后,您可以使用以下命令进入 WinRM 会话:
$username = '<admin-user>'
$pass = ConvertTo-SecureString -string '<password>' -AsPlainText -Force
$cred = New-Object -typename System.Management.Automation.PSCredential -argumentlist $username, $pass
Enter-PSSession -ComputerName <public-IP> -Credential $cred -SessionOption (New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck)
注意:默认情况下,WinRM over HTTP 和侦听器应该在您的计算机上设置和侦听。 HTTPS 未启用,因为不清楚从何处获取证书。但是,WinRM 使用消息级加密,因此它不完全是明文。您可以通过以下方式验证:
winrm e winrm/config/listener
这应该向您显示类似以下内容的侦听器:
Listener [Source="GPO"]
Address = *
Transport = HTTP
Port = 5985
Hostname
Enabled = true
URLPrefix = wsman
CertificateThumbprint
ListeningOn = 1.1.1.1
您还可以使用位于此处的快速入门模板:https://github.com/Azure/azure-quickstart-templates/tree/4b529b00eec1a48748e2f1ea0f305c0f07c87253/undefined . If the virtual machine already exists, you can manually copy some of the files and scripts from the same location. I added instructions here: http://blog.ricardovillalobos.com/?p=1871
我已成功将多个 Azure 虚拟机部署到 Azure 资源组。也就是说,我正在使用新的 Azure Resource Manager 部署模型从 JSON 模板部署虚拟机和相关资源。
我的问题是如何从我的笔记本电脑针对这些 VM 执行远程 PowerShell 脚本。我已经梳理了很多文章 - 但它们都展示了如何使用 Azure 中的经典虚拟机来实现。这个我已经知道并成功使用了。
现在,在使用 Azure 资源管理器创建的 Azure 虚拟机上,是否默认启用证书远程 PowerShell over SSL?如何连接 Enter-PSSession 或 Invoke-Command?
这适用于现有机器:通过 NIC 设置确保您的 VM 具有 public IP。接下来,如果您要使用笔记本电脑,请确保您的防火墙对 public 流量开放。这可以通过一个简单的 netsh 命令来完成:
netsh advfirewall firewall add rule name="WinRM HTTP" dir=in action=allow protocol=TCP localport=5985 profile=public
打开 public IP 和防火墙后,您可以使用以下命令进入 WinRM 会话:
$username = '<admin-user>'
$pass = ConvertTo-SecureString -string '<password>' -AsPlainText -Force
$cred = New-Object -typename System.Management.Automation.PSCredential -argumentlist $username, $pass
Enter-PSSession -ComputerName <public-IP> -Credential $cred -SessionOption (New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck)
注意:默认情况下,WinRM over HTTP 和侦听器应该在您的计算机上设置和侦听。 HTTPS 未启用,因为不清楚从何处获取证书。但是,WinRM 使用消息级加密,因此它不完全是明文。您可以通过以下方式验证:
winrm e winrm/config/listener
这应该向您显示类似以下内容的侦听器:
Listener [Source="GPO"]
Address = *
Transport = HTTP
Port = 5985
Hostname
Enabled = true
URLPrefix = wsman
CertificateThumbprint
ListeningOn = 1.1.1.1
您还可以使用位于此处的快速入门模板:https://github.com/Azure/azure-quickstart-templates/tree/4b529b00eec1a48748e2f1ea0f305c0f07c87253/undefined . If the virtual machine already exists, you can manually copy some of the files and scripts from the same location. I added instructions here: http://blog.ricardovillalobos.com/?p=1871