简体   繁体   中英

Programmatically obtaining Azure Active Directory tenant name from ID

How can I get an AAD tenant name (not necessarily mine), from a GUID? This would be via the REST API ideally, but the Azure CLI/Powershell works too.

I found an answer here , but it requires going to the Azure Portal.

There are also plenty of links here and elsewhere on obtaining the tenant ID from the name, but I'm going in the opposite direction.

You can get the tenant name (and some other details) for the signed-in user by calling the /organization endpoint in MS Graph API: https://docs.microsoft.com/en-us/graph/api/organization-get?view=graph-rest-1.0 .

Request: GET https://graph.microsoft.com/v1.0/organization

Response:

HTTP/1.1 200 OK
Content-type: application/json
Content-length: 411

{
  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#organization",
  "value": [
    {
      "assignedPlans": [
        {
          "assignedDateTime": "datetime-value",
          "capabilityStatus": "capabilityStatus-value",
          "service": "service-value",
          "servicePlanId": "servicePlanId-value"
        }
      ],
      "businessPhones": [
        "businessPhones-value"
      ],
      "city": "city-value",
      "country": "country-value",
      "countryLetterCode": "countryLetterCode-value",
      "displayName": "displayName-value"
    }
  ]
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM