Connect-MsolService with service principals to get Get-MsolAccountSku for Get-MsolUser

Wallis, John (INFOSYS) 1 Reputation point
2020-07-01T16:27:20.887+00:00

How can I get licence data from Get-MsolAccountSku for Get-MsolUser without logging in via Connect-MsolService as a user?
I would like to use a service principle but don't know the call.

Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
20,541 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Saurabh Sharma 23,791 Reputation points Microsoft Employee
    2020-07-01T21:01:39.663+00:00

    @WallisJohnINFOSYS-5992 It is not possible to use Get-MsolAccountSku with connecting to msol-service and using a service principal. I suggest you to Microsoft Graph API to get the license details. You need to hit the endpoint - https://graph.microsoft.com/v1.0/subscribedSkus to get all SKUs. If you want to get only specific information then you need to use $select like this - https://graph.microsoft.com/v1.0/subscribedSkus?$select = Skuid,skupartnumber, consumedUnits, prepaidunits

    Here is the output for your reference. You can follow the documentation for details.
    11192-get-subscribedskus-microsoftgraph.png

    Now, if you want to use this endpoint from an application service principal, then you need to register the application in Azure Active Directory, provide API permissions for Microsoft Graph to the application. Minimum required permission for using application context is User.Read.All as listed in the above documentation link.
    Please refer to Get access without a user to understand the concepts of calling Microsoft Graph API with application context with no logged in user.

    Also, if you want to call Microsoft Graph using PowerShell then you need to do some scripting as detailed in this blog.


    Please do not forget to "Accept the answer" wherever the information provided helps you to help others in the community.

    1 person found this answer helpful.