gpt4 book ai didi

azure - 使用托管标识启动 Azure VM Runbook

转载 作者:行者123 更新时间:2023-12-05 04:45:57 24 4
gpt4 key购买 nike

我正在尝试运行 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

我在我的环境中使用一个具有托管身份的虚拟机来启动另一台虚拟机进行了测试。

输出:

enter image description here

引用:

Install the Azure Az PowerShell module | Microsoft Docs

关于azure - 使用托管标识启动 Azure VM Runbook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69000813/

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