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

Wallis, John (INFOSYS) 1 Reputation point

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

    @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 - to get all SKUs. If you want to get only specific information then you need to use $select like this -$select = Skuid,skupartnumber, consumedUnits, prepaidunits

    Here is the output for your reference. You can follow the documentation for details.

    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.