41

Created Powershell Azure function and trying to use "az" commands under that function app. As per docs, function runtime should resolve "az" and other module dependencies. but it doesn't work for me.

ERROR: The term 'az' 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. Microsoft.Azure.WebJobs.Script.Rpc.RpcException : Result: ERROR: The term 'az' is not recognized as the name of a cmdlet, function, script file, or operable program.

I want to run some "az" command under function app without manually uploading modules. Is it powershell Preview version issue or something I need to correct?

requirement.psd1

@{
Az = '2.*'
}

enter image description here

Pankaj Rawat
  • 4,037
  • 6
  • 41
  • 73
  • 2
    If you mean the Azure CLI, you can take a look at the [issue](https://stackoverflow.com/questions/56544059/azure-cli-commands-not-working-inside-azure-function-apps-portal). – Charles Xu Sep 18 '19 at 09:18
  • If I will copy CLI directory, probably it will work. then what is the use of requirement.psd1? – Pankaj Rawat Sep 18 '19 at 09:22
  • 4
    PLEASE do not post **_pictures_** of code, errors, or sample data. why should anyone be forced to squint at your image when _you already have it as text_. also, why force those who want to help you to type in the test code _when you already have it as text_. – Lee_Dailey Sep 18 '19 at 09:22
  • First of all, Azure CLI is not the PowerShell module for the function. So you can not install the CLI module like the PowerShell modules nomally. – Charles Xu Sep 18 '19 at 09:25

7 Answers7

44

For those who get these error in local while trying to access AZ, try this command below in an admin PowerShell instance.

Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows -OutFile .\AzureCLI.msi; Start-Process msiexec.exe -Wait -ArgumentList '/I AzureCLI.msi /quiet'; rm .\AzureCLI.msi

You can get more details about installation @ https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-windows?view=azure-cli-latest&tabs=azure-powershell

Make sure you restart the powershell instance

Karthikeyan VK
  • 5,310
  • 3
  • 37
  • 50
31

"Az" in the context of PowerShell probably means the Az module, with cmdlets like Add-AzAccount etc.

"az" is the cross-platform CLI, which is not a PowerShell module.

Pankaj Rawat
  • 4,037
  • 6
  • 41
  • 73
juunas
  • 54,244
  • 13
  • 113
  • 149
28

I got this error because I had not installed CLI. I was sent this link which downloaded the required install:

https://aka.ms/installazurecliwindows

Charlie S
  • 4,366
  • 6
  • 59
  • 97
7

Two ways you can solve this issue.

Install below installation file for Azure CLI in windows.

https://aka.ms/installazurecliwindows

(OR)

Install using PowerShell the below command.

Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows -OutFile .\AzureCLI.msi; Start-Process msiexec.exe -Wait -ArgumentList '/I AzureCLI.msi /quiet'; rm .\AzureCLI.msi

More details: https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-windows?view=azure-cli-latest&tabs=azure-cli

Sathiamoorthy
  • 8,831
  • 9
  • 65
  • 77
0

I can see PowerShell 7.x and later is the recommended version.

You can check Powershell version using below command

$PSVersionTable.PSVersion

https://learn.microsoft.com/en-us/powershell/azure/install-az-ps?view=azps-6.2.0

NOTE

PowerShell 7.x and later is the recommended version of PowerShell for use with the Azure Az PowerShell module on all platforms.

Radhakrishnan
  • 564
  • 4
  • 6
0

Run this to fix: Install-Module AzureAD -Force Install-module AzureADPreview -Force Install-Module -Name MSOnline -Force Import-Module Az -Force Install-Module Az -Force

0

Download this then this problem will not occur. https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-windows?tabs=azure-cli

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 05 '21 at 05:43