RunBookでのモジュールインストールについて

清水雄樹 21 Reputation points
2021-07-12T08:39:02.803+00:00

ご担当者様

掲題の「Runbookでのモジュールインストールについて」についてお聞きしたいことがございます。

RunBookでVM停止処理(言語:PowerShell)の実装を検討しておりますが
以下エラーメッセージが表示され処理が実行されません。

System.Management.Automation.CommandNotFoundException: The term 'Stop-AzVM' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

ソースコードのなかでモジュールのインストールまたはインポートが必要かと
推測しておりますがStop-AzVMコマンド実行にあたって
必要な手順のご教示をお願い致します。

以上、よろしくお願いします。

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,254 questions
{count} votes

Accepted answer
  1. Andreas Baumgarten 108.7K Reputation points MVP
    2021-07-12T09:46:41.21+00:00

    Hi @清水雄樹 ,

    to use Stop-AzVM in a Runbook you need to import 2 modules in your Azure Automation Account first. The order is important, because the Az.Compute depends on Az.Accounts

    1. Az.Accounts
    2. Az.Compute

    Click on both modules and import the modules.

    113807-image.png

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten


1 additional answer

Sort by: Most helpful
  1. tbgangav-MSFT 10,416 Reputation points
    2021-07-12T09:24:16.103+00:00

    Translated to English:

    Hi @清水雄樹 ,

    Yes, you would have to make sure the cmdlet's related module is imported in your Azure Automation account.

    In general you would receive below mentioned error if the cmdlet's related module is not imported.

    System.Management.Automation.CommandNotFoundException: The term 'xxxxxxx' is not recognized as the name of a cmdlet, function, script file, or accurately program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

    In your case, I would recommend to successfully import Az.Compute module in your Azure Automation account and then try to execute the runbook.

    Follow the steps provided here (https://learn.microsoft.com/azure/automation/shared-resources/modules#import-az-modules) to import a module in an Azure Automation account.

    Let me know if you have further questions with regards to it.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.