Powershell中的Microsoft Azure配置JSON模板输出
大家好,我的社区 我在Microsoft Azure资源调配方面遇到问题,我正在尝试访问物联网中心或事件中心等资源的SharedAccessPolicyKey。我正在尝试使用listKeys函数,并在模板JSON文件中输出:Powershell中的Microsoft Azure配置JSON模板输出,json,powershell,azure,azure-iot-hub,azure-keyvault,Json,Powershell,Azure,Azure Iot Hub,Azure Keyvault,大家好,我的社区 我在Microsoft Azure资源调配方面遇到问题,我正在尝试访问物联网中心或事件中心等资源的SharedAccessPolicyKey。我正在尝试使用listKeys函数,并在模板JSON文件中输出: "outputs": { "hubKeys": { "value": "[listKeys(resourceId('Microsoft.Devices/IotHubs', parameters('hubName')), '2016-02-03')]", "t
"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”吗?我尤其需要“服务”的主密钥
我可以用打印机打印对象
$Key = New-AzureRmResourceGroupDeployment (deleted parameters for this post)
Write-Output $Key.Outputs.hubKeys
我已经尝试过像$Key.Outputs.hubKeys.value.Parents.values这样的东西。。。。还有无数其他方式。有人知道如何获得价值吗
谢谢,
Arno该示例说明了实现这一点的一种方法。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')]"
}
}