gpt4 book ai didi

azure - 启动-AzVM : Cannot bind parameter 'DefaultProfile' when running an Azure runbook

转载 作者:行者123 更新时间:2023-12-02 07:44:20 26 4
gpt4 key购买 nike

我正在研究这个official tutorial from MS Azure team运行 PowerShell Workflow Runbook 来启动 VM。但是当我启动以下 Runbook ( from step 6 of the tutorial ) 时,出现如下错误。 问题:我可能缺少什么,我们如何解决该问题?

备注:Start-AzVM来自Az.Compute module我已经导入了。

运行手册代码:

workflow MyFirstRunbook-Workflow
{
# Ensures that you do not inherit an AzContext in your runbook
Disable-AzContextAutosave –Scope Process

$Conn = Get-AutomationConnection -Name AzureRunAsConnection
Connect-AzAccount -ServicePrincipal -Tenant $Conn.TenantID -ApplicationId $Conn.ApplicationID -CertificateThumbprint $Conn.CertificateThumbprint

$AzureContext = Get-AzSubscription -SubscriptionId $Conn.SubscriptionID

Start-AzVM -Name 'vm-cs-web01' -ResourceGroupName 'rg-cs-ansible1' -AzContext $AzureContext
}

错误:

Start-AzVM : Cannot bind parameter 'DefaultProfile'. Cannot convert the "a76c7e8f-210d-45e5-8f5e-525015b1c881" value of 
type "Deserialized.Microsoft.Azure.Commands.Profile.Models.PSAzureSubscription" to type
"Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer".
At MyFirstRunbook-Workflow:11 char:11
+
+ CategoryInfo : InvalidArgument: (:) [Start-AzVM], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Azure.Commands.Compute.StartAzureVMCommand

最佳答案

看起来文档中存在错误,在这种情况下,应该使用 Set-AzContext 来设置订阅,而不是使用 Get-AzSubscription 来获取订阅,更改如下命令,就可以正常工作了。

workflow MyFirstRunbook-Workflow
{
# Ensures that you do not inherit an AzContext in your runbook
Disable-AzContextAutosave –Scope Process

$Conn = Get-AutomationConnection -Name AzureRunAsConnection
Connect-AzAccount -ServicePrincipal -Tenant $Conn.TenantID -ApplicationId $Conn.ApplicationID -CertificateThumbprint $Conn.CertificateThumbprint

$AzureContext = Set-AzContext -SubscriptionId $Conn.SubscriptionID

Start-AzVM -Name 'vm-cs-web01' -ResourceGroupName 'rg-cs-ansible1' -AzContext $AzureContext
}

enter image description here

关于azure - 启动-AzVM : Cannot bind parameter 'DefaultProfile' when running an Azure runbook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64957072/

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