Search code examples
azureazure-active-directorymicrosoft-graph-apiazure-sdk-.netazure-sdk

How can you detect which edition of Azure AD is in use via C#?


I need to determine if the edition of AzureAD in use is Premium or not.

How do I determine that in C#?


Solution

  • You can make use of Microsoft Graph APIs, either through Microsoft Graph .NET Client Library or through direct HTTP calls. The relevant API is:

    Also, note that for information about edition of Azure AD you could have a mix of services enabled in the same Azure AD and licenses are purchased/assigned on a per user basis.

    SubscribedSkus API mentioned above is pretty detailed and it gives you information about enabled capabilities as well as number of licenses available, consumed etc.

    Here's a similar thread on MSDN forums, you should also look at, it only talks about portal but still concept is relevant: How to check Azure AD edition.

    Here is an example that will print all active subscribed SKUs that include an Azure AD Premium service plan:

    // There are various Azure AD versions and editions. Here we're only counting
    // Azure AD Premium Plan 1 and Azure AD Premium Plan 2. 
    var azureAdPlans = new[] { "AAD_PREMIUM", "AAD_PREMIUM_P2" };
    
    // Get all subscribed SKUs
    var subscribedSkus = graphClient
        .SubscribedSkus
        .Request().GetAsync().GetAwaiter().GetResult();
    
    // Filter down the results to only active subscribed SKUs with Azure AD service plans.
    var skusWithAzureAd = subscribedSkus
        .Where(sku => (sku.CapabilityStatus == "Enabled" || sku.CapabilityStatus == "Warning")
                    && (sku.ServicePlans.Any(p => azureAdPlans.Contains(p.ServicePlanName))));
    
    // Print out the results
    foreach (var sku in skusWithAzureAd)
    {
        Console.WriteLine(
            "{0} ({1}/{2} seats used)", 
            sku.SkuPartNumber, 
            sku.ConsumedUnits, 
            sku.PrepaidUnits.Enabled + sku.PrepaidUnits.Warning);
    }