在Runbook中使用时找不到"Start-AzVM"命令 [英] Cannot find the 'Start-AzVM' command when used in a runbook
问题描述
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?
印本代码:
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
}
错误:
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 }'
推荐答案
Az.Compute
模块,因此您需要将此模块导入您的自动化帐户
Start-AzVM
is from the Az.Compute
module, so you need to import this module into your Automation Account.
要导入此模块,请转到自动化帐户->模块->浏览图库->搜索Az.Compute->导入
To import this module, go to Automation Account -> Modules -> Browse Gallery -> Search Az.Compute -> Import
如果要导入所有 Az.*
模块,则只需导入库中的 Az
模块.要将其导入您的自动化帐户,请转到自动化帐户->模块->浏览图库->搜索Az->导入.
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.
这篇关于在Runbook中使用时找不到"Start-AzVM"命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!