1
votes

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

1
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 aka.ms/installazurecliwindows to get the msi for azDhruv Patel
it is running perfectly fine in local... but not in azure functions app, portalpappu_kutty
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
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 - docs.microsoft.com/en-us/cli/azure/…. 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. Thanksbharathn-msft
Also see if this link helps you.docs.microsoft.com/en-us/azure/azure-functions/…. Thanksbharathn-msft

1 Answers

5
votes

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