The Get-MgUserLicenseDetail cmdlet retrieves detailed information about the licenses assigned to a user in Microsoft 365. This information includes the specific licenses and service plans assigned to the user.
Prerequisites
To use the Get-MgUserLicenseDetail cmdlet,
- You should have M365 administrator role assigned to you.
- You should possess "User.Read.All" or "Directory.Read.All" Graph API permission scope.
Basic Syntax
Here’s the basic syntax of the Get-MgUserLicenseDetail cmdlet: Get-MgUserLicenseDetail -UserId <String>
[<CommonParameters>]
- -UserId <String>: Use this parameter to specify the ID of the user for whom you want to retrieve license details. The UserId can be the user's UserPrincipalName (email) or ObjectId (GUID).
- <CommonParameters>: These are common parameters supported by many PowerShell cmdlets. They provide additional functionality such as specifying the output format, error handling, and more..
Usage Examples
Get License Details of a Specific User I
You should pass in the User Id or the UserPrincipalName to the Get-MgUserLicenseDetail cmdlet.
Get License Details of a Specific User II
You can also pass -All to Get-MgUserLicenseDetail cmdlet. In this case, the console requires you to supply the UserPrincipalName or User Id to get the user license details.
Get License Details of Multiple Users
You can also get the license details of multiple users by looping the user list and executing Get-MgUserLicenseDetail cmdlet.
$users = @("kimmy@7xh7fj.onmicrosoft.com","samadmin@7xh7fj.onmicrosoft.com","LeeG@7xh7fj.onmicrosoft.com")
foreach($user in $users) {
Get-MgUserLicenseDetail -UserId $user
}
Exporting License Details of Multiple Users to CSV File
The best way to get license of multiple users is to use Get-MgUser cmdlet along with Get-MgUserLicenseDetail cmdlet and export the license details to a CSV file.
$users = Get-MgUser -All
foreach($user in $users) {
Get-MgUserLicenseDetail -UserId $user.Id | Export-Csv -Path "d:/WeekyUserLicenseDetails.csv" -NoTypeInformation -Append
}
Getting the Service Plans
If you format-list the output from Get-MgUserLicenseDetail cmdlet, you'll get the service plans associated with the user.
Get-MgUserLicenseDetail -UserId "samadmin@7xh7fj.onmicrosoft.com" | Format-List
Find Disabled Service Plans for a User
Connect-MgGraph -Scopes "User.Read.All", "Directory.Read.All"
$UserId = "user@domain.com"
Get-MgUserLicenseDetail -UserId $UserId |
ForEach-Object {
$License = $_
$License.ServicePlans |
Where-Object { $_.ProvisioningStatus -ne "Success" } |
Select-Object `
@{Name="SkuPartNumber";Expression={$License.SkuPartNumber}},
ServicePlanName,
ServicePlanId,
ProvisioningStatus,
AppliesTo
}
What this script does
This script retrieves the licenses assigned to a user and identifies service plans that are not successfully provisioned.
Why this example is useful
This helps admins troubleshoot cases where a user has a license assigned but cannot access a specific Microsoft 365 service such as Exchange Online, Teams, SharePoint, or Planner.
Tips for Using Get-MgUserLicenseDetail
Here are some tips to keep in mind while using the Get-MgUserLicenseDetail cmdlet in Microsoft Graph PowerShell:
- Ensure Appropriate Permissions: Make sure you have the necessary permissions to run the Get-MgUserLicenseDetail cmdlet. Typically, you need the User.Read.All or Directory.Read.All permission.
- Authentication: Always authenticate to Microsoft Graph using Connect-MgGraph before running the cmdlet. Specify the required permissions to ensure you have access to the necessary data.
- Filtering Results: If you only need specific license details, filter the results using PowerShell filtering techniques to reduce the amount of data you need to process.
- Combining with Other Cmdlets: Combine Get-MgUserLicenseDetail with other cmdlets like Get-MgUser to get detailed user information along with license details.
- Exporting Data: Export the retrieved license details to a CSV file for further analysis and reporting. This is useful for audits and compliance checks.
- Handling Errors: Use error handling mechanisms to manage any issues that arise while running the cmdlet. This ensures your scripts are robust and can handle unexpected situations.
Use Cases for Get-MgUserLicenseDetail Cmdlet
- Audit License Usage: Regularly audit user licenses in your organization to ensure that licenses are being used efficiently and that there are no unused or underused licenses.
- License Management: Retrieve and manage user licenses to ensure that all necessary services are available to users and that costs are controlled.
- Scripting and Automation: Use this cmdlet in scripts to automate the process of retrieving license information and integrating it with other management tasks.
Frequently Asked Questions
- Can I retrieve license details for multiple users in a single call?
- Is there a way to check whether a user has access to specific Microsoft 365 services (e.g., Exchange, Teams)?
- Why do some users return no data when using
Get-MgUserLicenseDetail? - Can Get-MgUserLicenseDetail show disabled service plans?
No, Get-MgUserLicenseDetail works on a per-user basis. You need to loop through each user to gather license details in bulk.
Yes, the ServicePlans property in the output shows enabled or disabled status for individual services tied to the license.
This typically happens when the user does not have any license assigned or if the wrong user ID was specified.
Yes. The ServicePlans property shows individual service plans under each license. You can review the ProvisioningStatus value to identify whether a service plan is enabled, disabled, or not successfully provisioned.
Get-MgUserLicenseDetail -UserId "user@domain.com" |
Select-Object -ExpandProperty ServicePlans
SkuPartNumber refers to the assigned license, such as ENTERPRISEPACK or SPE_E3. ServicePlanName refers to an individual service inside that license, such as Exchange Online, Teams, SharePoint, or Planner.
A single license can contain multiple service plans.
Possible Errors and Solutions
| Error Message | Cause | Solution |
|---|---|---|
| Resource not found for the segment ‘userId’ | Invalid or misspelled user ID or UPN |
Ensure the user exists and pass the correct UserId parameter. Try using:Get-MgUser -UserPrincipalName <UPN> to validate.
|
| Access denied. Check permissions and try again. | Missing Graph API permissions. |
Make sure your app or session has the required delegated or application permission:User.Read.All or Directory.Read.All.
|
| Empty output despite valid user | The user does not have any licenses assigned. |
Confirm the license assignment using:Get-MgUser -UserId
|
Get-MgUserLicenseDetail not recognized |
The module or version may not support the cmdlet. |
Ensure you're using the latest version of the Microsoft.Graph module and that it's properly imported. Run: Update-Module Microsoft.Graph if needed.
|
The
Get-MgUserLicenseDetail cmdlet returns a detailed list of enabled service plans for each license assigned to the user — including services like Exchange, Teams, and SharePoint.This is especially helpful for auditing, troubleshooting access issues, or validating what apps a user should be able to access.
If a user has no licenses assigned,
Get-MgUserLicenseDetail will return an empty array — not an error.Always verify that the user is licensed before querying this cmdlet, especially when working in bulk or building automated reports.
The
Get-MgUserLicenseDetail cmdlet can be used to generate license reports that help with internal compliance checks or billing audits.You can easily verify which service plans (like Exchange, Teams, or SharePoint) are being utilized across assigned licenses — ensuring proper cost optimization.
Related Articles:
Using Find-GraphMgPermission in Graph PowerShellUsing Find-GraphMgCommand in Graph PowerShell
Using Get-MgDirectoryRole in Graph PowerShell
Connect to Microsoft 365 Using PowerShell
How to Create Bulk Users in Office 365 Using Graph PowerShell?
Create Microsoft 365 Group Using Microsoft Graph PowerShell
Block Microsoft 365 User Using Microsoft Graph PowerShell
Assign Microsoft 365 License Using Graph PowerShell
Microsoft 365 User Management Using Graph PowerShell
Checking Group Membership in Microsoft 365
Bulk Assign Microsoft 365 License
Find Inactive Users in Microsoft 365
Using Powershell Graph Search Query
Using Powershell Graph Filter Query
Using Where-Object In Graph PowerShell
Using Expand Property In Graph PowerShell
Using Select Object In Graph PowerShell
Using -Contains Operator In Graph PowerShell
Add User to Multiple Microsoft 365 Groups Using Graph PowerShell
Get Microsoft 365 User Location Using Graph PowerShell
Import Microsoft 365 Groups from CSV File Using Graph PowerShell
Microsoft 365 Group User Import Using Graph PowerShell