首页 > 解决方案 > 从 azure CLI 获取租户名称

问题描述

我想THIS-THING-HERE.onmicrosoft.com使用 Azure CLI 检索租户名称。我真的无法在文档中找到。

编辑:当我调用 azure account list 时,我没有在提供的域中获得用户名,因为我使用公司电子邮件登录:

[
  {
    "cloudName": "AzureCloud",
    "id": "46ee2f65-7112-4c96-ad0a-3ff6ca22a615",
    "isDefault": true,
    "name": "Visual Studio Professional",
    "state": "Enabled",
    "tenantId": "1caf5d6b-58cb-40e6-88b3-eb9ab9c0c010",
    "user": {
      "name": "a.krajniak@avanade.com",
      "type": "user"
    }
  },
  {
    "cloudName": "AzureCloud",
    "id": "1efd84d6-173f-42cc-80db-7b2c17eb0edd",
    "isDefault": false,
    "name": "Microsoft Azure Enterprise",
    "state": "Enabled",
    "tenantId": "c48d02ad-7efd-4910-9b51-ebb7a4b75379",
    "user": {
      "name": "a.krajniak@avanade.com",
      "type": "user"
    }
  }
]

标签: azureazure-cli

解决方案


你可以使用这个命令:

az ad signed-in-user show --query 'userPrincipalName' | cut -d '@' -f 2 | sed 's/\"//'

这将占用用户 upn 并完成最后一部分


推荐阅读