1

I have powershell scripts which is running locally.But those scripts not running insite function apps > powershell (windows) machine.

az login --service-principal -u $ServicePrincipalId -p $ServicePrincipalPass --tenant $ServicePrincipalTenant

Getting below when i run the script

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

since i dont have az cli installed in the windows machine, i have added below line to install az command in my script.

Install-Module -Name Az -AllowClobber  -Scope CurrentUser

Getting access issue while installing the az.

2019-06-11T12:42:59.698 [Warning] WARNING: InternalWebProxy: Could not find a part of the path 'D:\Program Files (x86)\SiteExtensions\Functions\2.0.12507\32bit\workers\powershell\runtimes\win-x86\lib\netcoreapp2.1\ref'.
2019-06-11T12:42:59.843 [Warning] WARNING: Win32Helpers: Could not find a part of the path 'D:\Program Files (x86)\SiteExtensions\Functions\2.0.12507\32bit\workers\powershell\runtimes\win-x86\lib\netcoreapp2.1\ref'.
2019-06-11T12:43:05.023 [Warning] WARNING: User declined to install module (Az).

even -Force is not working. need to know what is causing the issue.

Note :- The script is perfectly running in local windows machine. the issue is when try to run on portal > functionapp> timertrigger

Attaching azure function app creating with windows machine

enter image description here

Getting error after adding cli folder into kudu

> 2019-06-13T12:29:40.510 [Error] ERROR:   File
> "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-core\azure\cli\core\commands\__init__.py", line 523, in execute Microsoft.Azure.WebJobs.Script.Rpc.RpcException :
> Result: ERROR:   File
> "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-core\azure\cli\core\commands\__init__.py", line 523, in execute Exception:   File
> "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-core\azure\cli\core\commands\__init__.py", line 523, in execute

kudu console

enter image description here

pappu_kutty
  • 2,378
  • 8
  • 49
  • 93
  • I believe you are trying to run a az cli command. Installing az module does not install the az executable that you are trying to run. The solution to this is installing az cli. Use https://aka.ms/installazurecliwindows to get the msi for az – Dhruv Patel Jun 11 '19 at 12:54
  • it is running perfectly fine in local... but not in azure functions app, portal – pappu_kutty Jun 11 '19 at 12:58
  • The command you used to install the Azure CLI is not correct. It's used to install the Azure PowerShell. So it means you do nothing to install the Azure CLI. – Charles Xu Jun 12 '19 at 01:21
  • Not quite sure if I understand the requirement. Are you looking to execute azure cli commands for operations on function apps ? this link might give you more context on that - https://learn.microsoft.com/en-us/cli/azure/functionapp?view=azure-cli-latest. If not, are you trying to execute a azure cli command with in a timetrigger based function app ? and why windows machine was getting in to the picture ? Can you please share any screen shots you might have so that it would better understand your scenario. Thanks – bharathn-msft Jun 12 '19 at 02:25
  • Also see if this link helps you.https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-powershell. Thanks – bharathn-msft Jun 12 '19 at 02:32
  • @bharathn-msft i am having script which has az commands. which i am running in windows machine which is in preview mode.. – pappu_kutty Jun 12 '19 at 07:22
  • @bharathn-msft attached image – pappu_kutty Jun 12 '19 at 07:24

2 Answers2

5

As the error shows that you do not install the Azure CLI in the environment. To install the Azure CLI, a possible way is to copy the whole CLI directory that you installed in the local machine to your function KUDU path /home.

In the test, the copy path in the function KUDU is D:/home/CLI2/.

Test code:

D:/home/CLI2/wbin/az.cmd login --service-principal -u 'xxxxxx' -p 'xxxxxx' --tenant 'xxxxxx' | Write-Host

The screenshot of the output:

enter image description here

Charles Xu
  • 29,862
  • 2
  • 22
  • 39
  • getting error after adding cli folder to kudu.. is something i am missing here?-- i have added the error in the question block. – pappu_kutty Jun 13 '19 at 12:33
  • @pappu_kutty Where do you copy the folder? And which CLI folder do you copy? And what is the script you want to run? – Charles Xu Jun 14 '19 at 01:54
  • i have copied folder inside D:home .. i have cli from my local as you mentioned. and i am running this script D:/home/CLI2/wbin/az.cmd login --service-principal -u $ServicePrincipalId -p $ServicePrincipalPass --tenant $ServicePrincipalTenant – pappu_kutty Jun 14 '19 at 10:07
  • @pappu_kutty How do you set the variables? And do you just run the script one time? Try more times. I assume that why the error shows the file exception in path "C:". – Charles Xu Jun 15 '19 at 12:18
  • i run through function app timer trigger, even i tried in kudu console, it is not working. please check this link, which i have raised https://github.com/Azure/Azure-Functions/issues/1246 – pappu_kutty Jun 17 '19 at 08:46
  • @pappu_kutty Do you copy the whole CLI directory to the kubu path /home? not just the CLI2/wbin/az.cmd. And can you show the PowerShell script you use? – Charles Xu Jun 17 '19 at 08:51
  • yes i copied whole path into kudu/Cli directory, i have attached the image for your reference – pappu_kutty Jun 17 '19 at 09:10
  • i ran in cmd and powershell in kudu console.. geting below error. ERROR: The command failed with an unexpected error. Here is the traceback: ERROR: 'NoneType' object is not callable Traceback (most recent call last): File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\knack\knack\cli.py", line 206, in invoke – pappu_kutty Jun 17 '19 at 09:22
  • @pappu_kutty The error seems you install the CLI through the pip? Or there is a path set in the environment? – Charles Xu Jun 18 '19 at 05:45
  • @pappu_kutty Maybe there is an unexpected error. The final way, recreate your function and do the steps again. – Charles Xu Jun 19 '19 at 08:40
  • @pappu_kutty No screen share. We just can talk in the SO. So the chat is OK. – Charles Xu Jun 19 '19 at 08:44
  • i have drag and dropped cli folders in kudu – pappu_kutty Jun 19 '19 at 08:45
  • @pappu_kutty That is one way. But it would interrupt if it continues too long. So I suggest you compress the directory and upload it. Then decompress it in the kudu. – Charles Xu Jun 19 '19 at 08:49
  • @pappu_kutty Yes, there is a lot of files in the CLI directory. But Azure CLI is not installed in the function environment. If you want to use it, you need to copy it yourself. – Charles Xu Jun 20 '19 at 08:19
  • it is working, after i copied zip and dropping in kudu console.. you rock!!!!. i did manual copy,, which i missed few files... – pappu_kutty Jun 24 '19 at 08:41
  • @pappu_kutty Glad to hear that. – Charles Xu Jun 24 '19 at 08:42
0

As others have suggested here, you need to install this:

https://aka.ms/installazurecliwindows

In my case, I just had a corrupted installation of the Azure Client, and repairing it solved my issue.

ps. close your Powershell window before it