How do I import module Az.Compute

Rick Powell 5 Reputation points
2023-04-29T17:29:12.83+00:00

I am following learn.microsoft.com/en-us/azure/automation/learn/automation-tutorial-runbook-textual to create runbook to start VM using managed identities

Test return error:

Failed
At line:16 char:1
+ Start-AzVM -Name $VMName -ResourceGroupName $resourceGroup -DefaultPr ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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 }'

Start-AzVm is suppose to be found in the module Az.Compute.

When I attempt to add the module, I get the error below> How do I proceed?

Error importing the module Az.Compute. Import failed with the following error: Orchestrator.Shared.AsyncModuleImport.ModuleImportException: An error occurred when trying to import the module to an internal PowerShell session. Either the module dependencies are not imported correctly or the module is unsupported. Internal Error Message: The type initializer for 'Microsoft.Azure.Commands.Common.AzModule' threw an exception. . at Orchestrator.Activities.SetModuleVersion.GetPsModuleVersion(String moduleName, String moduleFullPath, Guid accountId, Guid moduleVersionId, InitialSessionState defaultSessionState) at Orchestrator.Activities.SetModuleVersion.InsertModuleVersion(String moduleName, ModuleLanguage moduleLanguage, String pythonModuleVersion, String moduleFullyQualifiedName, ActivitiesMetadataWorkflowExtension activitiesMetadataWorkflowExtension, Guid accountId, Guid moduleVersionId, Int64 moduleContentByteSize, ContentUriInfo contentUri, String storageUri, Int32 moduleVersion) at Orchestrator.Activities.SetModuleVersion.ExecuteInternal(CodeActivityContext context, String moduleName, ModuleLanguage moduleLanguage, String pythonModuleVersion, String modulePath, Guid accountId, Guid moduleVersionId, Int64 moduleContentByteSize, String storageUri, Int32 moduleVersion) at Orchestrator.Activities.SetModuleVersion.Execute(CodeActivityContext context) at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager) at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation).

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
6,335 questions
Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,000 questions
{count} vote

4 answers

Sort by: Most helpful
  1. Prrudram-MSFT 19,961 Reputation points
    2023-04-30T19:03:18.2733333+00:00

    Hello @Rick Powell

    It looks like the Az.Compute module is not installed properly on your system. To proceed, you can try to install the Az.Compute module by running the following command in an elevated PowerShell session:

    Install-Module -Name Az.Compute -AllowClobber -Force
    

    This command will install the Az.Compute module and its dependencies. Once the module is installed, you can import it by running the following command:

    Import-Module -Name Az.Compute
    

    After importing the module, you should be able to use the Start-AzVM command in your runbook without any issues. If you still face issues, please let me know and I'll try my best to help you.

    Please accept answer and upvote if the above information is helpful for the benefit of the community.


  2. yuvaraj j 6 Reputation points Microsoft Employee
    2023-05-31T10:39:27.7133333+00:00

    Hello SHISHIR,

    i would recommend to update the module, which would fix the missing /corrupted library

     Update-Module -Name Az -Force

     

    0 comments No comments

  3. Rick Powell 5 Reputation points
    2023-05-31T17:34:04.6866667+00:00

    This is not yet ready to work. It clearly states in modules that you must use and older version of Az.Account. When you finally get that installed and need to install Az.Resources. Az.Resources updates Az.Accounts to latest version which as the messages in Modules states will not work and you are back to SAME PROBLEM. HAVE TO WAIT UNTIL THIS MICROSOFT GARBAGE GROWS UP.

    0 comments No comments

  4. Rick Powell 5 Reputation points
    2023-05-31T18:50:53.8566667+00:00

    Workaround given at https://github.com/Azure/azure-powershell/issues/21647 allows Az.Accounts and Az.Resources to be installed.

    0 comments No comments