2016-04-25 59 views
2

你好社區#1,微軟Azure部署JSON模板輸出在PowerShell中

我與微軟的Azure部署的問題,我試圖訪問SharedAccessPolicyKeys像物聯網,集線器或事件集線器資源。

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

}

當我輸出Windows PowerShell中返回的對象,但它看起來是這樣的:我與listKeys功能和輸出這些模板JSON文件中嘗試這種

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 ....和無數的其他方式。有誰知道如何獲得價值?

謝謝, 阿諾

回答

1

樣品here示出了實現這個的一種方式。 ARM模板創建一個IoT Hub和Azure Stream Analytics作業,使用生成的鍵值連接到集線器。

這些片段總結了關鍵部分:

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