3
votes

I am attempting to install the az cmdlet onto Kudu for my Azure Function. I am currently following this guide:

How to install a PowerShell module in an Azure Function

... however - I am still getting the following error within my Azure Function:

az : 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. at run.ps1: line 1

Steps I have done till now:

  • Created a module folder under D:\home\site\wwwroot\Communication_with_Azure_Container_Registry\>
  • Within the module folder I have added the contents of azure-cli/2.0.35/..., (which looks like this): enter image description here

    ... Azure Function code is very simple to proof out the ability to install the cmdlet:

    if (-not (Get-Module -Name "az"))
    {
      Write-Output "azure-cli not installed";
    }
    else
    {
      Write-Output "azure-cli installed";
    }
    
    $test = 'az --help'
    Invoke-Expression $test
    Write-output `n$test
    

Question:

  • Is there something within my configuration that is not allowing for the az cmdlet to install?
  • Is there an alternative way to gain access to the azure-cli without implementing the node module?
3
The question you're linking to is about the Azure PowerShell cmdlets, not the az-cli, which is a cross-platform cli that runs on python. I'm unaware of any way to install the az-cli on azure app service through kudu. You probably can get it to work if you get python 3.6 on the machine, and then get the cli there manually, but I never tried it and I have no idea if it'll actually run. - ahmelsayed
I upgraded and was able to run python.exe -m pip install azure-cli but I am not sure where that was saved ... - jdave
What is your goal, to run the Azure CLI 2 (python) from an Azure Function OR to run the Azure Powershell Commandlets from an Azure Function? If your goal is the former I think your are going to run into issues authenticating via the CLI to actually run any commands. - KWilson
@KWilson my goal is to authenticate via the azure-cli from my Azure Function in order to communicate with my Azure Container Registry - to invoke a Docker container as a Azure Instance Container. - jdave

3 Answers

2
votes

I solved the following part of your problem

az : 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. at run.ps1: line 1

If you execute

Test-Path -Path 'C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin'

You will probably get False. This means that you need to install the Azure CLI eg from https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-windows?view=azure-cli-latest

0
votes

I haven't testing this myself, but according to https://blogs.msdn.microsoft.com/powershell/2017/02/24/using-powershell-modules-in-azure-functions/ you should be able to do an Import-Module. In their example...

Write-Output “Loading Wunderlist Module”
import-module ‘D:\Home\site\wwwroot\HttpTriggerPowerShellDemo\Modules\Wunderlist\1.0.10\Wunderlist.psm1’
$Result = Get-Help Get-WunderlistUser | Out-String
Write-Output $Result