如何使用 powershell 函数应用程序获取认知服务帐户密钥?
How to get cognitive services account key using powershell function app?
我已经创建了认知服务帐户。我想获取认知服务帐户密钥并使用 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
以上脚本能够列出云中的键 shell 但不能列出 powershell 函数应用程序中的键。
您不能像在您之前从该站点安装 Az.CognitiveServices
的本地计算机上那样简单地调用 Import-Module Az.CognitiveServices
。但是您必须将本地安装包中的所有文件复制到 Azure 中 Function App 内的特定文件夹中。
1.Install Az.CognitiveServices
在本地并转到其文件夹以获取其中的所有内容。
2.Go 到你的函数 KUDU。单击 CMD>site>wwwroot>yourFunctionName
然后创建一个名为 modules
.
的目录
3.Simply 拖放 将所有文件从本地 powershell 模块位置拖放到上面创建的 Azure Function App 文件夹(模块)。
4.Include Az.CognitiveServices
运行.ps1 文件中的 PowerShell 模块,如下例所示:
Import-Module "D:\home\site\wwwroot\HttpTrigger1\modules\Az.CognitiveServices.psd1"
5.Then 运行 下面的脚本用 $Key.Key1
来指定 Key1.
$Key = Get-AzCognitiveServicesAccountKey -ResourceGroupName $resourceGroup -Name $AccountName
Write-Host "account key 1 = " $Key.Key1
我已经创建了认知服务帐户。我想获取认知服务帐户密钥并使用 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
以上脚本能够列出云中的键 shell 但不能列出 powershell 函数应用程序中的键。
您不能像在您之前从该站点安装 Az.CognitiveServices
的本地计算机上那样简单地调用 Import-Module Az.CognitiveServices
。但是您必须将本地安装包中的所有文件复制到 Azure 中 Function App 内的特定文件夹中。
1.Install Az.CognitiveServices
在本地并转到其文件夹以获取其中的所有内容。
2.Go 到你的函数 KUDU。单击 CMD>site>wwwroot>yourFunctionName
然后创建一个名为 modules
.
3.Simply 拖放 将所有文件从本地 powershell 模块位置拖放到上面创建的 Azure Function App 文件夹(模块)。
4.Include Az.CognitiveServices
运行.ps1 文件中的 PowerShell 模块,如下例所示:
Import-Module "D:\home\site\wwwroot\HttpTrigger1\modules\Az.CognitiveServices.psd1"
5.Then 运行 下面的脚本用 $Key.Key1
来指定 Key1.
$Key = Get-AzCognitiveServicesAccountKey -ResourceGroupName $resourceGroup -Name $AccountName
Write-Host "account key 1 = " $Key.Key1