【问题标题】:Azure Function - PowerShell, installing az cmdlet :: The term 'az' is not recognized as the name of a cmdletAzure 函数 - PowerShell,安装 az cmdlet :: 术语“az”未被识别为 cmdlet 的名称
【发布时间】:2018-11-22 01:54:51
【问题描述】:

我正在尝试将 az cmdlet 安装到 Kudu 上以用于我的 Azure Function。我目前正在关注本指南:

How to install a PowerShell module in an Azure Function

...但是 - 我的 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

到目前为止我已经完成的步骤:

  • D:\home\site\wwwroot\Communication_with_Azure_Container_Registry\> 下创建了一个module 文件夹
  • module 文件夹中,我添加了azure-cli/2.0.35/... 的内容,(如下所示):

    ... Azure Function 代码非常简单地证明了安装 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
    

问题

  • 我的配置中是否存在不允许安装az cmdlet 的内容?
  • 是否有其他方法可以在不实现node 模块的情况下访问azure-cli

【问题讨论】:

  • 您链接到的问题是关于 Azure PowerShell cmdlet,而不是 az-cli,它是在 python 上运行的跨平台 cli。我不知道通过 kudu 在 azure app 服务上安装 az-cli 的任何方式。如果你在机器上安装了 python 3.6,你可能可以让它工作,然后手动获取 cli,但我从未尝试过,我不知道它是否会真正运行。
  • 我升级并能够运行python.exe -m pip install azure-cli,但我不确定它保存在哪里...
  • 您的目标是什么,从 Azure 函数运行 Azure CLI 2 (python) 或从 Azure 函数运行 Azure Powershell Commandlet?如果您的目标是前者,我认为您将在通过 CLI 进行身份验证以实际运行任何命令时遇到问题。
  • @KWilson 我的目标是通过我的 Azure 函数中的 azure-cli 进行身份验证,以便与我的 Azure 容器注册表通信 - 将 Docker 容器作为 Azure 实例容器调用。

标签: powershell azure azure-functions azure-cli


【解决方案1】:

我解决了你的以下部分问题

az:术语“az”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确并重试。在 run.ps1:第 1 行

如果你执行

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

你可能会得到 False。这意味着您需要安装 Azure CLI,例如从 https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-windows?view=azure-cli-latest

【讨论】:

    【解决方案2】:

    我自己没有对此进行测试,但根据https://blogs.msdn.microsoft.com/powershell/2017/02/24/using-powershell-modules-in-azure-functions/,您应该能够执行导入模块。在他们的例子中......

    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
    

    【讨论】:

      【解决方案3】:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-06-12
        • 2012-06-22
        • 2021-12-22
        • 2019-10-12
        • 2017-12-11
        • 2021-12-09
        • 2020-02-25
        相关资源
        最近更新 更多