簡體   English   中英

通過Azure遠程通過Powershell訪問Azure虛擬機

[英]Accessing an azure vm through Powershell remote from Azure Automation

我正在嘗試通過Powershell從Azure Automation進行遠程處理來訪問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

如果要使用Azure Automation Runbook訪問虛擬機,則需要使用Hybrid Runbook Workers 這是安裝在您的一台服務器上並向您的Azure自動化帳戶注冊的代理。 然后,您可以從此處在Hybrid Runbook Worker上執行Runbook。

然后,您可以設置您的運行手冊要在混合運行手冊工人執行,這將有效地執行運行手冊,就好像它是你的服務器上。

如果您的Runbook首先在Azure中執行某些操作,那么我強烈建議拆分您的Runbook,以便一個人在Azure中執行操作,然后調用另一個傳遞適當參數但在Hybrid Runbook Worker上執行的Runbook。 您可以使用PowerShell在Hybrid Runbook Worker上執行Azure Automation Runbook,如以下示例所示:

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

當虛擬機上沒有公共IP地址時,可以使用此選項。

另一個選擇是使用WinRM,證書和Azure Key Vault的組合,以便能夠使用Enter-PSSession進行連接。 在Azure資源管理器中為虛擬機設置WinRM訪問的文檔中詳細介紹了有關設置的更多信息。 但是請注意,僅當您的虛擬機具有公共IP時,才能使用此方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM