azure vm run command script

Ori Poria 21 Reputation points
2021-10-18T12:03:51.5+00:00

I try to run the simple command of 'az version' from a VM with the Run Command Script but I get this error: "The term 'az' is not recognized as the name of a cmdlet...".

But when I run this command from the VM that I connect it with Remote Desktop Connection it works.

What should I do in order to operate 'az' commands from the Run Command Script?

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,065 questions
0 comments No comments
{count} votes

Accepted answer
  1. Andreas Baumgarten 95,181 Reputation points MVP
    2021-10-18T18:57:28.353+00:00

    Hi @Ori Poria ,

    you are right. My fault sorry. It's the path that is missing to run Azure CLI ;-)

    Here you go:

    Write-Output "First option"  
    $env:Path += ";C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin"  
    az version  
      
    Write-Output "Second option"  
    & "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin\az.cmd" version  
    

    141425-image.png

    ----------

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

    Regards
    Andreas Baumgarten

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Andreas Baumgarten 95,181 Reputation points MVP
    2021-10-18T12:34:19.333+00:00

    Hi @Ori Poria ,

    az is an Azure CLI command. Is AZ CLI installed on the VM?

    ----------

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

    Regards
    Andreas Baumgarten