Runbookで使用すると、「Start-AzVM」コマンドが見つかりません

Nov 22 2020

私はMSAzureチームからのこの公式チュートリアルに取り組んでおり、を実行してPowerShell Workflow runbookを開始しVMます。しかし、次のRunbookを開始すると(チュートリアルのステップ6から)、以下に示すエラーが発生します。質問:私が見逃している可能性があるものと、問題を解決するにはどうすればよいですか?

rinbookコード

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 }'

回答

1 RoadRunner Nov 22 2020 at 11:52

Start-AzVMはAz.Computeモジュールからのものであるため、このモジュールを自動化アカウントにインポートする必要があります。

このモジュールをインポートするには、[自動化アカウント]-> [モジュール]-> [ギャラリーの参照]-> [Az.Computeの検索]-> [インポート]に移動します。

すべてのAz.*モジュールをインポートする場合はAz、ギャラリーからモジュールをインポートするだけです。これを自動化アカウントにインポートするには、[自動化アカウント]-> [モジュール]-> [ギャラリーの参照]-> [Azの検索]-> [インポート]に移動します。