2

您好 Stackoverflow 社区,

我遇到了 Microsoft Azure Provisioning 的问题,我正在尝试访问 SharedAccessPolicyKeys 以获取 IoT-Hubs 或 Event-Hubs 等资源。我正在尝试使用 listKeys 函数并在模板 JSON 文件中输出这些:

    "outputs": {
"hubKeys": {
  "value": "[listKeys(resourceId('Microsoft.Devices/IotHubs', parameters('hubName')), '2016-02-03')]",
  "type": "object"
}

}

当我在 Windows Powershell 中输出返回的对象时,它看起来像这样:

    Type                       : Array
    IsReadOnly                 : False
    HasValues                  : True
    First                      : {keyName, primaryKey, secondaryKey, rights}
    Last                       : {keyName, primaryKey, secondaryKey, rights}
    Count                      : 5
    Parent                     : {{
                                   "keyName": "iothubowner",
                                   "primaryKey": "dZVFGkIysIgVRKjxlZsCWdk6KGa4rpBFlY6BOLmaiD8=",
                                   "secondaryKey": "HtRYETAdgja/TBSS3sVTshKaGzZWMLbZC6GR60emSV4=",
                                   "rights": "RegistryWrite, ServiceConnect, DeviceConnect"
                                 } {
                                   "keyName": "service",
                                   "primaryKey": "DGOujP2tBTiTTdKxukTx7umeYFFlDEhoih7fb0tP3i8=",
                                   "secondaryKey": "B+6j1nfEc59GAeJQNakNKolTBoR9kc5W+TUNzRXmDpc=",
                                   "rights": "ServiceConnect"
                                 } {
                                   "keyName": "device",
                                   "primaryKey": "qxmRJVH0yVhSkLEz8JaHhtDJaDofpw4SEKkZNlBwp7c=",
                                   "secondaryKey": "RhUuME9EnnUsE2sixswaiTofKsVVfCQNIllwkHgY/8A=",
                                   "rights": "DeviceConnect"
                                 } {
                                   "keyName": "registryRead",
                                   "primaryKey": "pEpHrL4amd9+7pvl6uCiYHL3rZhxV76tZ1P9bERO6Xc=",
                                   "secondaryKey": "6h4UBKd4WPkdpUfl0Hi3G5YKgB3LmtDMbgXDYx3eKrk=",
                                   "rights": "RegistryRead"
                                 } {
                                   "keyName": "registryReadWrite",
                                   "primaryKey": "HpCxKVa1686A8vOfNVBUzYSe2YJmKIwwAzxUh5DokuY=",
                                   "secondaryKey": "PGeYYID9y6cClqGD1rl4koLNySc7kOGK6VuNlBiwqmo=",
                                   "rights": "RegistryWrite"
                                 }}
    Root                       : {value}
    Next                       : 
    Previous                   : 
    Path                       : value
    LineNumber                 : 0
    LinePosition               : 0
    AllowNew                   : True
    AllowEdit                  : True
    AllowRemove                : True
    SupportsChangeNotification : True
    SupportsSearching          : False
    SupportsSorting            : False
    IsSorted                   : False
    SortProperty               : 
    SortDirection              : Ascending
    IsFixedSize                : False
    SyncRoot                   : System.Object
    IsSynchronized             : False

我的问题:谁能告诉我如何访问不同“keyName”对象中的“primaryKey”?特别是我需要“服务”的 PrimaryKey。

我可以打印对象

    $Key = New-AzureRmResourceGroupDeployment (deleted parameters for this post)
    Write-Output $Key.Outputs.hubKeys

我已经尝试过 $Key.Outputs.hubKeys.value.Parents.values.... 和无数其他方法。有谁知道如何获得价值?

谢谢,阿诺

4

1 回答 1

1

此处的示例说明了实现此目的的一种方法。ARM 模板创建一个 IoT 中心和 Azure 流分析作业,该作业使用生成的键值连接到该中心。

这些片段总结了关键部分:

/* Create IoT Hub */
{
  "apiVersion": "2016-02-03",
  "type": "Microsoft.Devices/IotHubs",
  "name": "[variables('iotHubName')]",
  "location": "[resourceGroup().location]",
  "sku": "[parameters('iotHubSku')]"
},

/* Part of the ASA definition */
"datasource": {
  "type": "Microsoft.Devices/IotHubs",
  "properties": {
    "iotHubNamespace": "[variables('iotHubName')]",
    "sharedAccessPolicyName": "[variables('iotHubKeyName')]",
    "sharedAccessPolicyKey": "[listKeys(resourceId('Microsoft.Devices/IotHubs/Iothubkeys', variables('iotHubName'), variables('iotHubKeyName')), '2016-02-03').primaryKey]",
    "consumerGroupName": "[variables('archiveJobConsumerGroupName')]"
  }
}
于 2016-05-06T08:49:17.383 回答