Start-AzVM: Der Parameter 'DefaultProfile' kann beim Ausführen eines Azure-Runbooks nicht gebunden werden

Nov 22 2020

Ich arbeite an diesem offiziellen Tutorial des MS Azure-Teams , um a auszuführen und a PowerShell Workflow runbookzu starten VM. Wenn ich jedoch das folgende Runbook starte ( ab Schritt 6 des Tutorials ), wird der unten gezeigte Fehler angezeigt. Frage : Was fehlt mir möglicherweise und wie können wir das Problem beheben?

Anmerkung : Start-AzVM stammt aus dem Az.Compute-Modul , das ich bereits importiert habe.

Runbook-Code :

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
}

Fehler :

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

Antworten

2 JoyWang Nov 23 2020 at 02:12

Es sieht so aus, als wäre es ein Fehler im Dokument. In diesem Szenario sollte Set-AzContextdas Abonnement festgelegt werden, anstatt Get-AzSubscriptiondas Abonnement abzurufen. Ändern Sie den Befehl wie unten beschrieben. Es funktioniert einwandfrei.

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
}