bash - az cli 选择对象的第一个值

标签 bash azure command-line-interface

az webapp Identity show 命令:https://learn.microsoft.com/en-us/cli/azure/webapp/identity?view=azure-cli-latest#az-webapp-identity-show

将返回以下结果:

{
  "principalId": null,
  "tenantId": null,
  "type": "UserAssigned",
  "userAssignedIdentities": {
    "/subscriptions/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx": {
      "clientId": "xxx",
      "principalId": "xxx"
    }
  }
}

现在我只想返回 /subscriptions/xxxxxxxxxxxxxxxxxxxxxxxxxxx 值。如何使用 --query 选项过滤此值?我已经尝试过了

--query userAssignedIdentities

        "/subscriptions/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx": {
          "clientId": "xxx",
          "principalId": "xxx"
        }
      }

但是要在这里获得第一把 key 还需要一些东西。什么?

最佳答案

使用以下 Azure CLI cmdlet

az webapp identity show -name <WebAppName> -g <ResoureGroupName> --query  "keys(userAssignedIdentities)" -o tsv

enter image description here

或者,您可以使用以下 PowerShell cmdlet 提取分配给 Azure Web 应用的 userAssignedIdentities 的资源 ID。

$identity=Get-AzWebApp -Name <WebAppName> -ResourceGroupName "<ResourceGroupName>" | select -ExpandProperty Identity
$identity.UserAssignedIdentities.Keys  

enter image description here

关于bash - az cli 选择对象的第一个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73936430/

相关文章:

ruby-on-rails - 全新的 Heroku CLI 安装认证失败

linux - 如何根据powershell中的变量在gcc6和gcc8之间切换

linux - Bash 脚本 : Diference between "$(command)" and `command`

linux - 如何并行化我的 bash 脚本以与 `find` 一起使用而不面临竞争条件?

java - java bash路径中的空格

php - 运行 PHP 的内置服务器和 Symfony 的 PHP 服务器的区别

Linux 脚本意外的文件结束错误

function - 如何获取 Azure FunctionApp 绑定(bind)的返回绑定(bind)属性

c# - Pechkin 与 Windows Azure

Azure Cosmos DB - 每个用户访问不同的数据 (SQL)