'The term 'az' is not recognized as the name of a cmdlet, function, script file, or operable program

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



Solution 1:[1]

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

Make sure you restart the powershell instance

Solution 2:[2]

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

https://aka.ms/installazurecliwindows

Solution 3:[3]

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

Solution 4:[4]

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.

Solution 5:[5]

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

Solution 6:[6]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Charlie Seligman
Solution 3
Solution 4 Radhakrishnan
Solution 5 user2347380
Solution 6 Mohammad Umar