Azure 运行手册 (ARM) 中的新 PSSession
New-PSSession in an Azure-runbook (ARM)
对于经典门户 (ASM) 中的 Azure VM,我能够获得
Get-AutomationPSCredential
和 所需的凭据
-ConnectionURI
和 Connect-AzureVM.ps1
。
使用这两个参数,我能够在 Azure-runbook 中成功执行 New-PSSession
。
Q 我应该怎么做才能在 Azure-runbook 中打开到 Azure-VM (ARM) 的 PS-Session?
更新
Runbook (ARM) 中的命令
$vmSession = New-PSSession -ConnectionUri 'https://xxx.yyy.cloudapp.azure.com:5985' -Credential $creds -SessionOption (New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck)
错误信息
New-PSSession : [xxx.yyy.cloudapp.azure.com] Connecting to
remote server xxx.yyy.cloudapp.azure.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.
根据您的错误,5985 端口似乎被某些防火墙阻止了。您可以使用 telnet
来测试连通性。
telnet xxx.yyy.cloudapp.azure.com 5985
如果失败,您应该额外检查:
在 Windows 防火墙(入站规则)上打开端口 5985。
在 Azure NSG(入站规则)上打开端口 5985。注意NSG可能关联网卡或子网,最好全部检查。
在您的服务器 VM 上,执行 cmdlet。
winrm 快速配置
确保您可以访问端口 5985,然后在您的本地 PC 上进行测试,然后在 Azure Runbook 上进行测试。
我使用以下 cmdlet,它对我有用。
New-PSSession -ConnectionUri 'http://IP:5985' -Credential $creds -SessionOption (New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck)
注意:如果您的服务器没有配置证书,则不能使用https
,您应该使用http
。
PS C:\Users\v-shshui> New-PSSession -ConnectionUri 'http://*.*.*.*:5985' -Credential $creds -SessionOption (New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck)
Id Name ComputerName ComputerType State ConfigurationName Availability
-- ---- ------------ ------------ ----- ----------------- ------------
7 Session7 *.*.*.* RemoteMachine Opened Microsoft.PowerShell Available
此外,如果你想使用https
,你需要配置一个证书,如图link。
更新
如果您想 winrm
到 Azure Runbook 中的 VM,您应该使用 https
。这意味着您应该在 Azure NSG 和 Windows 防火墙上打开端口 5986(默认情况下)。此外,您需要在 Azure VM 上添加新证书。
对于经典门户 (ASM) 中的 Azure VM,我能够获得
Get-AutomationPSCredential
和 所需的凭据
-ConnectionURI
和Connect-AzureVM.ps1
。
使用这两个参数,我能够在 Azure-runbook 中成功执行 New-PSSession
。
Q 我应该怎么做才能在 Azure-runbook 中打开到 Azure-VM (ARM) 的 PS-Session?
更新
Runbook (ARM) 中的命令
$vmSession = New-PSSession -ConnectionUri 'https://xxx.yyy.cloudapp.azure.com:5985' -Credential $creds -SessionOption (New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck)
错误信息
New-PSSession : [xxx.yyy.cloudapp.azure.com] Connecting to remote server xxx.yyy.cloudapp.azure.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.
根据您的错误,5985 端口似乎被某些防火墙阻止了。您可以使用 telnet
来测试连通性。
telnet xxx.yyy.cloudapp.azure.com 5985
如果失败,您应该额外检查:
在 Windows 防火墙(入站规则)上打开端口 5985。
在 Azure NSG(入站规则)上打开端口 5985。注意NSG可能关联网卡或子网,最好全部检查。
在您的服务器 VM 上,执行 cmdlet。
winrm 快速配置
确保您可以访问端口 5985,然后在您的本地 PC 上进行测试,然后在 Azure Runbook 上进行测试。
我使用以下 cmdlet,它对我有用。
New-PSSession -ConnectionUri 'http://IP:5985' -Credential $creds -SessionOption (New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck)
注意:如果您的服务器没有配置证书,则不能使用https
,您应该使用http
。
PS C:\Users\v-shshui> New-PSSession -ConnectionUri 'http://*.*.*.*:5985' -Credential $creds -SessionOption (New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck)
Id Name ComputerName ComputerType State ConfigurationName Availability
-- ---- ------------ ------------ ----- ----------------- ------------
7 Session7 *.*.*.* RemoteMachine Opened Microsoft.PowerShell Available
此外,如果你想使用https
,你需要配置一个证书,如图link。
更新
如果您想 winrm
到 Azure Runbook 中的 VM,您应该使用 https
。这意味着您应该在 Azure NSG 和 Windows 防火墙上打开端口 5986(默认情况下)。此外,您需要在 Azure VM 上添加新证书。