问题
I am working on this official tutorial from MS Azure team to run a PowerShell Workflow runbook
to start a VM
. But when I start the following runbook (from step 6 of the tutorial), I get the error shown below. Question: What I may be missing, and how can we resolve the issue?
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
}
Error:
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 }'
回答1:
Start-AzVM is from the Az.Compute module, so you need to import this module into your Automation Account.
To import this module, go to Automation Account -> Modules -> Browse Gallery -> Search Az.Compute -> Import
If you want to have all Az.*
modules imported, then you can just import the Az module from the gallery. To import this for your automation account, go to Automation Account -> Modules -> Browse Gallery -> Search Az -> Import.
来源:https://stackoverflow.com/questions/64950705/cannot-find-the-start-azvm-command-when-used-in-a-runbook