question

71824798 avatar image
0 Votes"
71824798 asked 71824798 commented

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

ご担当者様

掲題の「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
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

こんにちは @71824798,

はい、コマンドレットの関連モジュールがAzureAutomationアカウントにインポートされていることを確認する必要があります。

一般に、コマンドレットの関連モジュールがインポートされていない場合、以下のエラーが発生します。

System.Management.Automation.CommandNotFoundException:「xxxxxxx」という用語は、コマンドレット、関数、スクリプトファイル、または正確なプログラムの名前として認識されません。 名前のスペルを確認するか、パスが含まれている場合は、パスが正しいことを確認して、再試行してください。

あなたの場合、Azure AutomationアカウントにAz.Computeモジュールを正常にインポートしてから、Runbookを実行することをお勧めします。

ここに記載されている手順(https://docs.microsoft.com/azure/automation/shared-resources/modules#import-az-modules)に従って、AzureAutomationアカウントにモジュールをインポートします

それに関してさらに質問があれば私に知らせてください。

0 Votes 0 ·
AndreasBaumgarten avatar image
0 Votes"
AndreasBaumgarten answered 71824798 commented

Hi @71824798 ,

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


image.png (147.0 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @71824798 ,

Did the answer work for you? Are there any additional questions to this topic?

If you found the answer helpful, it would be great if you please mark it "Accept as answer". This will help others to find answers in Q&A

----------
Regards
Andreas Baumgarten

0 Votes 0 ·

Thank you for the easy-to-understand explanation!
The error disappeared and the process proceeded.
It was helpful!

0 Votes 0 ·
tbgangav-MSFT avatar image
0 Votes"
tbgangav-MSFT answered tbgangav-MSFT edited

Translated to English:

Hi @71824798,

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://docs.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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.