Search code examples
azure-active-directoryazure-cli

How to get primary domain name in azure active directory using azure cli


Is there a way to get the primary domain name using Azure Cli az ad command

Azure Ad primary domain


Solution

  • There is no direct command to get Primary domain using Azure CLI.

    Alternatively, you can make use of either Microsoft Graph Explorer or PowerShell like below:

    In my Azure Portal, my Primary domain looks like this:

    enter image description here

    Using Microsoft Graph Explorer, you can run query like below:

    GET https://graph.microsoft.com/v1.0/domains?$select=id
    

    Response:

    enter image description here

    You can run the above query in Azure CLI using az rest method like below:

    az rest --method get --url 'https://graph.microsoft.com/v1.0/domains?$select=id'
    

    Response:

    enter image description here

    Using PowerShell, you can run command like below:

    Connect-AzureAD 
    Get-AzureADDomain
    

    Response:

    enter image description here

    References:

    List domains - Microsoft Graph v1.0 | Microsoft Docs

    Get-AzureADDomain (AzureAD) | Microsoft Docs