gpt4 book ai didi

powershell - 从 Azure 自动化通过 Powershell 远程访问 azure vm

转载 作者:行者123 更新时间:2023-12-03 04:19:31 27 4
gpt4 key购买 nike

我正在尝试通过 azure 自动化的 powershell 远程处理来访问 azure 虚拟机。我们订阅内的所有虚拟机都没有公共(public) IP(只有私有(private) 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 自动化 Runbook 访问虚拟机,则需要使用 Hybrid Runbook Workers 。这是安装在您的一台服务器上并使用您的 Azure 自动化帐户重新注册的代理。然后,您可以从这里在混合 Runbook Worker 上执行 Runbook。

然后您可以设置您的runbook要在混合 Runbook Worker 上执行,这将有效地执行 Runbook,就像它在您的服务器上一样。

如果您的 Runbook 首先在 Azure 中执行某些操作,那么我强烈建议您拆分 Runbook,以便一个 Runbook 在 Azure 中执行操作,然后调用另一个 Runbook 传递适当的参数,但在混合 Runbook 辅助角色上执行。您可以使用 PowerShell 在混合 Runbook 辅助角色上执行 Azure 自动化 Runbook,如以下示例所示:

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

当您的虚拟机上没有公共(public) IP 地址时,可以使用此选项。

另一个选项是结合使用 WinRM、证书和 Azure Key Vault,以便能够使用 Enter-PSSession 进行连接。有关设置的更多信息,请参阅 Setting up WinRM access for Virtual Machines in Azure Resource Manager 的文档。 。但请注意,只有当您的虚拟机具有公共(public) IP 时,您才能使用此方法。

关于powershell - 从 Azure 自动化通过 Powershell 远程访问 azure vm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50449994/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com