Der Befehl 'Start-AzVM' kann nicht gefunden werden, wenn er in einem Runbook verwendet wird
Ich arbeite an diesem offiziellen Tutorial des MS Azure-Teams , um a auszuführen und a PowerShell Workflow runbook
zu 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?
Rinbook-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 :
Failed At line:11 char:1
+ Start-AzVM -Name 'vm-cs-web01' -ResourceGroupName 'rg-cs-ansible1' -A ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Cannot find the 'Start-AzVM' command. If this command is defined as a workflow, ensure it is defined before the workflow that calls it. If it is a command intended to run directly within Windows PowerShell (or is not available on this system), place it in an InlineScript: 'InlineScript { Start-AzVM }'
Antworten
Start-AzVMstammt aus dem Az.ComputeModul, daher müssen Sie dieses Modul in Ihr Automatisierungskonto importieren.
Um dieses Modul zu importieren, gehen Sie zu Automatisierungskonto -> Module -> Galerie durchsuchen -> Az.Compute durchsuchen -> Importieren
Wenn Sie alle Az.*
Module importieren möchten, können Sie das AzModul einfach aus der Galerie importieren . Um dies für Ihr Automatisierungskonto zu importieren, gehen Sie zu Automatisierungskonto -> Module -> Galerie durchsuchen -> Az durchsuchen -> Importieren .