【问题标题】:How to get cognitive services account key using powershell function app?如何使用 powershell 函数应用程序获取认知服务帐户密钥?
【发布时间】:2020-05-20 17:22:16
【问题描述】:

我创建了认知服务帐户。我想获取认知服务帐户密钥并使用 powershell 脚本将其存储在变量中。

我使用了以下脚本:

$resourceGroup = "Demo"

$AccountName = "DemoCs"

$Key = Get-AzCognitiveServicesAccountKey -ResourceGroupName $resourceGroup -Name $AccountName

Write-Host "account key 1 = " $Key

脚本执行后的结果是:

2020-05-20T08:30:31Z [信息] 信息:帐户密钥 1 = Microsoft.Azure.Commands.Management.CognitiveServices.Models.PSCognitiveServicesAccountKeys

上面的脚本可以列出 cloud shell 中的键,但不能在 powershell 函数应用中列出。

【问题讨论】:

    标签: azure powershell azure-cognitive-services azure-function-app


    【解决方案1】:

    您不能像在以前从该站点安装了Az.CognitiveServices 的本地计算机上那样简单地调用Import-Module Az.CognitiveServices。但是您必须将本地安装包中的所有文件复制到 Azure 中的 Function App 内的特定文件夹中。

    1.在本地安装Az.CognitiveServices并进入其文件夹获取其中的所有内容。

    2.转到你的函数 KUDU。点击CMD>site>wwwroot>yourFunctionName,然后创建一个名为modules的目录。

    3.只需将所有文件从本地 powershell 模块位置拖放到上面创建的 Azure Function App 文件夹(模块)。

    4.在 run.ps1 文件中包含 Az.CognitiveServices PowerShell 模块,如下例所示:

    Import-Module "D:\home\site\wwwroot\HttpTrigger1\modules\Az.CognitiveServices.psd1"
    

    5.然后使用$Key.Key1运行如下脚本来指定Key1。

    $Key = Get-AzCognitiveServicesAccountKey -ResourceGroupName $resourceGroup -Name $AccountName
    
    Write-Host "account key 1 = " $Key.Key1
    

    更多详情可以参考tutorialone

    【讨论】:

      猜你喜欢
      • 2014-09-07
      • 2022-11-19
      • 1970-01-01
      • 2018-09-20
      • 2022-08-19
      • 1970-01-01
      • 2017-09-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多