我正在尝试运行 Runbook 以使用托管标识启动 VM。使用 runas 帐户可以正常工作,但因为 Microsoft 表示建议使用托管身份,所以我想尝试一下。
这是我从互联网上获得的脚本的一部分,适用于 runas 帐户:
$ResourceGroupName = 'test'
$AzureVMName = 'test'
$connectionName = "AzureRunAsConnection"
try
{
# Get the connection "AzureRunAsConnection "
$servicePrincipalConnection=Get-AutomationConnection -Name $connectionName
"Logging in to Azure..."
Login-AzureRmAccount `
-ServicePrincipal `
-TenantId $servicePrincipalConnection.TenantId `
-ApplicationId $servicePrincipalConnection.ApplicationId `
-CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint
}
这是我现在尝试使用但不起作用的脚本:
Connect-AzAccount -Identity
$ResourceGroupName = 'test'
$AzureVMName = 'test'
"Starting Azure VM..."
Start-AzureRmVM -Name $AzureVMName -ResourceGroupName $ResourceGroupName
我总是收到以下错误:
环境
{[AzureChinaCloud、AzureChinaCloud]、[AzureCloud、AzureCloud]、[AzureGermanCloud、AzureGermanCloud]、[AzureUSGovernme... 正在启动 Azure 虚拟机... 运行Login-AzureRmAccount进行登录。
我尝试了很多方法,但无法使其正常工作......
最佳答案
如Thomas已经建议您在下面的代码中使用 2 个模块,即 "Az"
和 "AzureRM"
:
Connect-AzAccount -Identity
$ResourceGroupName = 'test'
$AzureVMName = 'test'
"Starting Azure VM..."
Start-AzureRmVM -Name $AzureVMName -ResourceGroupName $ResourceGroupName
因此,仅使用 Az
模块,如下所示:
Connect-AzAccount -Identity
$ResourceGroupName = 'ansumantest'
$AzureVMName = 'testVM'
"Starting Azure VM..."
Start-AzVM -Name $AzureVMName -ResourceGroupName $ResourceGroupName
我在我的环境中使用一个具有托管身份的虚拟机来启动另一台虚拟机进行了测试。
输出:
引用:
关于azure - 使用托管标识启动 Azure VM Runbook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69000813/