PS /home/ian> az network application-gateway identity show --gateway-name "xxx-inf-abc-wag" --resource-group "network-xxx"
{
"principalId": null,
"tenantId": null,
"type": "userAssigned",
"userAssignedIdentities": {
"/subscriptions/XXXXXXXXX-80b8-4447-b2a6-XXXXXXXXXX/resourcegroups/network-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/dev-gpp-wag-mi": {
"clientId": "DDDDDDDDD-eb2e-4836-898a-DDDDDDDDD",
"principalId": "UUUUUUUUUU-b7c8-43d2-80a2-UUUUUUUUUU"
}
}
}
我只是想从运行'az network application-gateway identity show'返回的上面json中检索字段'principalId'的值。
我想我需要加上"——查询……"之类的东西。我试过"——query .principalId"但这行不通。我知道我的"——query"的语法有问题。但不知道如何解决?
az network application-gateway identity show
使用以下查询表达式
$id=$(az network application-gateway identity show -g MyResourceGroup --gateway ag1 --query 'userAssignedIdentities."/subscriptions/XXXXXXXXX-80b8-4447-b2a6-XXXXXXXXXX/resourcegroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/id1".principalId' -o tsv)
az network application-gateway identity show -g MyResourceGroup --gateway-name ag1
给出如下输出:
{
"principalId": null,
"tenantId": null,
"type": "userAssigned",
"userAssignedIdentities": {
"/subscriptions/XXXXXXXXX-80b8-4447-b2a6-XXXXXXXXXX/resourcegroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/id1": {
"clientId": "DDDDDDDDD-eb2e-4836-898a-DDDDDDDDD",
"principalId": "UUUUUUUUUU-b7c8-43d2-80a2-UUUUUUUUUU"
}
}
}
由于键/subscriptions/XXXXXXXXX-80b8-4447-b2a6-XXXXXXXXXX/resourcegroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/id1
包含正斜杠和点字符(这是特殊字符),因此必须进行转义。
因此,关键字应该加双引号
使用另一个az命令解决…
$id = $(az ad sp list—display-name "XXX-abc-wag-mi"——查询[0]。Id——output tsv)