通过Powershell从Azure自动化远程访问azure vm [英] Accessing an azure vm through Powershell remote from Azure Automation

查看:78
本文介绍了通过Powershell从Azure自动化远程访问azure vm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过azure自动化通过powershell远程处理来访问azure vm.订阅中我们所有的虚拟机都没有公共IP(只有私有IP).我试图通过New-Pssession进行访问(如下所示),但是没有运气.

I am trying to access an azure vm via powershell remoting from azure automation. All our vms inside the subscription do not have public ips (only private ip). I have tried to access by New-Pssession (as below) , but no luck.

能否让我知道实现这一目标的其他方法?

Could you please let me know what are the other ways to achive this?

$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

推荐答案

如果要使用Azure Automation Runbook访问虚拟机,则需要使用

If you want to access Virtual Machines using Azure Automation Runbooks then you will need to use Hybrid Runbook Workers. This is an agent installed on one of your servers and registered back with your Azure Automation Account. From here you can then execute your runbook on your Hybrid Runbook Worker.

然后,您可以设置 runbook 要在Hybrid Runbook Worker上执行,这将像在服务器上一样有效地执行Runbook.

You can then setup your runbook to be executed on a Hybrid Runbook Worker, this will effectively execute the runbook as though it was on your server.

如果您的Runbook首先在Azure中执行某些操作,那么我强烈建议拆分您的Runbook,以使其中一个在Azure中执行操作,然后调用另一个通过适当参数但在混合Runbook Worker上执行的Runbook.您可以使用PowerShell在Hybrid Runbook Worker上执行Azure Automation Runbook,如以下示例所示:

If your runbook does some actions in Azure first, then I would highly recommend splitting out your runbooks so that one does actions in Azure then calls the other runbook passing the appropriate parameters but executing on the Hybrid Runbook Worker. You can use PowerShell to execute an Azure Automation Runbook on a Hybrid Runbook Worker as shown in the following example:

Start-AzureRmAutomationRunbook –AutomationAccountName "MyAutomationAccount" –Name "Test-Runbook" -RunOn "MyHybridGroup"

当虚拟机上没有公共IP地址时,可以使用此选项.

You can use this option when you don't have a public IP address on the virtual machine.

另一种选择是结合使用WinRM,证书和Azure Key Vault,以便能够使用 Enter-PSSession 进行连接..但是请注意,只有在虚拟机具有公共IP的情况下,才能使用此方法.

Another option is to use a combination of WinRM, certificates and Azure Key Vault to be able to connect using Enter-PSSession. More on setting this up is detailed in the documentation on Setting up WinRM access for Virtual Machines in Azure Resource Manager. Note however that you can only use this method when your Virtual Machine has a public IP.

这篇关于通过Powershell从Azure自动化远程访问azure vm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆