我的问题是:不使用powershell命令可以获得azure活动目录租户id吗?

我找到了这两个博客,有了这个帮助,我已经能够从powershell获得租户ID和订阅ID。这是找回房客的唯一方法吗?

在Windows PowerShell中获取Windows Azure活动目录租户ID

Windows Azure AD认证支持PowerShell

谢谢


当前回答

进入Azure门户> Azure活动目录。 在主屏幕上,您应该看到您的租户ID。

其他回答

从Java:

public static String GetSubscriptionTenantId (String subscriptionId) throws ClientProtocolException, IOException
{
    String tenantId = null;
    String url = "https://management.azure.com/subscriptions/" + subscriptionId + "?api-version=2016-01-01";

    HttpClient client = HttpClientBuilder.create().build();
    HttpGet request = new HttpGet(url);
    HttpResponse response = client.execute(request);

    Header[] headers = response.getAllHeaders();
    for (Header header : headers)
    {
        if (header.getName().equals("WWW-Authenticate"))
        {
            // split by '"' to get the URL, split the URL by '/' to get the ID
            tenantId = header.getValue().split("\"")[1].split("/")[3];
        }
    }

    return tenantId;
}

截至目前(06/07/2018),一个简单的方法是在Azure门户中运行Azure云Shell中的az帐户显示(需要存储帐户)。

——命令——

az account show

——命令输出——

{
  "environmentName": "AzureCloud",
  "id": "{Subscription Id (GUID)}",
  "isDefault": true,
  "name": "{Subscription Name}",
  "state": "Enabled",
  "tenantId": "{Tenant Id (GUID)}",
  "user": {
    "cloudShellID": true,
    "name": "{User email}",
    "type": "user"
  }
}

有关Azure Cloud Shell的更多详细信息,请参阅Azure Cloud Shell | Microsoft Docs概述。

时间会改变一切。我最近也想做同样的事情,然后想到了这个:

Note

添加02/17/2021

稳定的门户页面感谢Palec

添加12/18/2017

正如shadowbq所指出的,DirectoryId和TenantId都等同于表示ActiveDirectory租户的GUID。根据上下文的不同,这两个术语都可能被Microsoft文档和产品使用,这可能会令人困惑。

假设

您可以访问Azure传送门

解决方案

租户ID绑定到Azure中的ActiveDirectoy

导航到仪表板 导航到ActiveDirectory 导航到管理/属性 复制“目录ID”

Azure ActiveDirectory租户ID:

另一种方法是从应用注册中获取

Azure Active Directory ->应用程序注册->单击应用程序,它将显示租户ID,如下所示

如果您已经在您的机器中安装了Azure CLI 2.0,那么您应该能够使用以下命令获得您所属的订阅列表:

az login

如果你想看到一个表输出,你可以使用

az account get-access-token --query tenant --output tsv

或者你可以使用Rest API

租户-列表|微软文档