I would like to retrieve the tenant name THIS-THING-HERE.onmicrosoft.com
using Azure CLI. I can't really find in documentation.
EDIT: When I'm calling azure account list I don't get user name in the domain provided since I'm login with corporate email:
[
{
"cloudName": "AzureCloud",
"id": "46ee2f65-7112-4c96-ad0a-3ff6ca22a615",
"isDefault": true,
"name": "Visual Studio Professional",
"state": "Enabled",
"tenantId": "1caf5d6b-58cb-40e6-88b3-eb9ab9c0c010",
"user": {
"name": "[email protected]",
"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": "[email protected]",
"type": "user"
}
}
]
Sign in to the Azure portal. Select Azure Active Directory from the menu. The Azure Active Directory Overview page appears. To find the Azure AD tenant ID or primary domain name, look for Tenant ID and Primary domain in the Basic information section.
You can also list your subscriptions and view their IDs programmatically by using Get-AzSubscription (Azure PowerShell) or az account list (Azure CLI).
To see the subscription you're currently using or to get a list of available subscriptions, run the az account show or az account list command. Go to Learn to use Bash with the Azure CLI to see more examples of ways to use az account show . The --output parameter is a global parameter, available for all commands.
You could use this command:
az ad signed-in-user show --query 'userPrincipalName' | cut -d '@' -f 2 | sed 's/\"//'
this will take user upn and take the last part
To get the primary domain of an Azure tenant using bash, az cli, curl and jq:
$ az login
$ AZURE_TOKEN_ID=$(az account get-access-token --resource-type ms-graph --query accessToken --output tsv)
$ curl --header "Authorization: Bearer ${AZURE_TOKEN_ID}" --request GET 'https://graph.microsoft.com/v1.0/domains' | jq -r '.value[] | select(.isDefault == true) | {id}[]'
The result will be something like:
mydomain.onmicrosoft.com
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With