how to get string for assigned licenses from azure instead of guid RRS feed

  • Question

  • User389157859 posted

    i am trying to retrieve user assigned licenses from azure tenant. below is the partial view i am using to modify the "@html.displayfor " and view the list of assigned licenses in a table one after the other

    @using Microsoft.Azure.ActiveDirectory.GraphClient;
    @model IList<AssignedLicense>
    @foreach (var assignedLicense in Model)
        var a = assignedLicense.SkuId;
        @Html.DisplayFor(al => a)

    the code works fine, but it displays a guid instead of displaying the name of the licence 

    please help

    Wednesday, February 8, 2017 10:26 AM

All replies

  • User1724605321 posted

    Hi umangkachrani,

    Subscription SKU IDs and plan IDs can be read from the tenant object. For example, performing a GET request to https://graph.windows.net/myorganization/subscribedSkus returns the subscriptions available for the tenant of the signed-in user. These are returned as SubscribedSku entities and the SKU ID can be read from the skuId property. In client library , you could firstly get the subscribedSkus information available for the tenant :

                   IPagedCollection<ISubscribedSku> pagedCollection = await client.SubscribedSkus.ExecuteAsync();
                    List<SubscribedSku> skulist = new List<SubscribedSku>();
                    if (pagedCollection != null)
                            List<ISubscribedSku> skus = pagedCollection.CurrentPage.ToList();
                            foreach (ISubscribedSku sku in skus)
                            pagedCollection = await pagedCollection.GetNextPageAsync();
                        } while (pagedCollection != null);

    Then you could get the skuPartNumber property from according to the AssignedLicense of current user :

                 foreach (var item in user.AssignedLicenses)
                        var value = skulist.Single(x=>x.SkuId==item.SkuId).SkuPartNumber;

    Best Regards,

    Nan Yu

    Monday, February 27, 2017 7:38 AM