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

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

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

Windows Azure AD认证支持PowerShell

谢谢


当前回答

使用Azure CLI

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

其他回答

您可以运行一个简单的curl调用来获得azure订阅的租户id,而无需任何身份验证。

做一个卷曲调用:

https://management.azure.com/subscriptions/{订阅id} ? api版本= 2015-01-01

请求失败,但您将能够从响应报头中获得租户id。租户id出现在一行中,后面跟着“WWW-Authenticate: holder authorization_uri="https://login.windows.net/"

您可以使用curl -v来显示响应头。

xxx@Azure:~$ az ad sp create-for-rbac
Retrying role assignment creation: 1/36
{
  "appId": "401143c2-95ef-4792-9900-23e07f7801e7",
  "displayName": "azure-cli-2018-07-10-20-31-57",
  "name": "http://azure-cli-2018-07-10-20-31-57",
  "password": "a0471d14-9300-4177-ab08-5c45adb3476b",
  "tenant": "e569f29e-b008-4cea-b6f0-48fa8532d64a"
}

通过PowerShell匿名:

(Invoke-WebRequest https://login.windows.net/YOURDIRECTORYNAME.onmicrosoft.com/.well-known/openid-configuration|ConvertFrom-Json).token_endpoint.Split('/')[3]

如果你已经安装了Azure CLI,你可以运行下面的命令,

az account list

或者在~/.azure/credentials中找到它

PowerShell:

Add-AzureRmAccount #if not already logged in 
Get-AzureRmSubscription -SubscriptionName <SubscriptionName> | Select-Object -Property TenantId