【发布时间】:2018-10-31 04:16:17
【问题描述】:
我正在尝试通过 azure 自动化的 powershell 远程访问 azure vm。订阅中的所有虚拟机都没有公共 ip(只有私有 ip)。我曾尝试通过 New-Pssession 访问(如下),但没有运气。
能否请您告诉我实现此目标的其他方法是什么?
$connectionName = "AzureRunAsConnection"
$SPC = Get-AutomationConnection -Name $connectionName
Write-Output $SPC
Add-AzureRmAccount -ServicePrincipal -TenantId $SPC.TenantId -ApplicationId $SPC.ApplicationId -CertificateThumbprint $SPC.CertificateThumbprint
Get-AzureRmSubScription
Select-AzureRMSubscription -SubscriptionId 'XXXXXXXXXXXXXXX'
Get-AzureRMAutomationAccount | fl *
$username = 'XXXXXXX'
$password = 'XXXXXXXX'
$secpasswd = ConvertTo-SecureString $password -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential ($username, $secpasswd)
$S = New-PsSession -ComputerName XXXXXXXX -Credential $mycreds
Enter-PSSession -Session $S
【问题讨论】:
-
请参阅以下文档以使用 Enter-PSSession 访问 Azure VM:docs.microsoft.com/en-us/azure/virtual-machines/windows/winrm
-
@VikranthS 该解决方案仅适用于具有公共 IP 地址的虚拟机。该问题仅说明私有 IP 地址。
标签: powershell azure azure-virtual-machine azure-automation