16
votes

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

4
If you mean the Azure CLI, you can take a look at the issue. - Charles Xu
If I will copy CLI directory, probably it will work. then what is the use of requirement.psd1? - Pankaj Rawat
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
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

4 Answers

12
votes

"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.

7
votes

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

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://docs.microsoft.com/en-us/cli/azure/install-azure-cli-windows?view=azure-cli-latest&tabs=azure-powershell

3
votes

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

https://aka.ms/installazurecliwindows

0
votes

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

You can check Powershell version using below command

$PSVersionTable.PSVersion

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