【问题标题】:Microsoft Azure Provisioning JSON Template Output in PowershellPowershell 中的 Microsoft Azure 预配 JSON 模板输出
【发布时间】:2016-08-18 18:41:35
【问题描述】:

你好 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.... 以及无数其他方法。有谁知道如何获得价值?

谢谢, 阿诺

【问题讨论】:

    标签: json powershell azure azure-iot-hub azure-keyvault


    【解决方案1】:

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

    这些 sn-ps 总结了关键部分:

    /* 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')]"
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-15
      相关资源
      最近更新 更多