We have to export an Office 365 mailbox to PST file. An excellent way to…
Check Microsoft 365 user license is direct assigned or inherited from group
There are two methods to assign a Microsoft 365 license. One way is to assign the license directly, and the other is to add the user to a group linked to the license, known as group-based licensing. The preferable method is group-based licensing because it’s easier to maintain and for auditing purposes. In this article, you will learn how to check if a Microsoft 365 user license is direct assigned or inherited from a group.
Table of contents
Check user license assignment type in Microsoft Entra admin center
To check if the Microsoft 365 user license is direct assigned or inherited from a group in Microsoft Entra admin center, follow the below steps:
- Sign in to Microsoft Entra admin center
- Expand Identity > Billing > Licenses
- Click All products
- Click the Microsoft product name
- Check the column Assignment Paths if the user is direct assigned or inherited from a group
Note: It’s recommended to Assign Microsoft 365 licenses with group-based licensing and not direct so you can manage it easily.
Check user license assignment type with PowerShell
To check if the Microsoft 365 user license is direct assigned or inherited from a group with Microsoft Graph PowerShell, follow these steps:
Step 1. Install Microsoft Graph PowerShell
Run Windows PowerShell as administrator and Install Microsoft Graph PowerShell.
Install-Module Microsoft.Graph -Force
Install-Module Microsoft.Graph.Beta -AllowClobber -Force
Important: Always install the Microsoft Graph PowerShell and Microsoft Graph Beta PowerShell modules. That’s because some cmdlets are not yet available in the final version, and they will not work. Update both modules to the latest version before you run a cmdlet or script to prevent errors and incorrect results.
Step 2. Prepare Get-LicenseAssignment PowerShell script
Create two folders on the (C:) drive:
- Temp
- Scripts
Download the Get-LicenseAssignment.ps1 PowerShell script and place it in C:\scripts folder. The script will export the CSV file to the C:\temp folder.
Ensure the file is unblocked to prevent errors when running the script. Read more in the article Not digitally signed error when running PowerShell script.
Another option is to copy and paste the below code into Notepad. Give it the name Get-LicenseAssignment.ps1 and place it in the C:\scripts folder.
<#
.SYNOPSIS
Get-LicenseAssignment.ps1
.DESCRIPTION
The script will export all Microsoft 365 users license assignment to CSV file.
.LINK
www.alitajran.com/microsoft-365-user-license-direct-assigned-or-inherited-from-group/
.NOTES
Written by: ALI TAJRAN
Website: www.alitajran.com
LinkedIn: linkedin.com/in/alitajran
.CHANGELOG
V1.00, 03/04/2024 - Initial version
#>
# Connect to Microsoft Graph
Connect-MgGraph -Scopes "User.Read.All"
# Get all users using Get-MgUser with a filter
$users = Get-MgUser -All -Property AssignedLicenses, LicenseAssignmentStates, DisplayName |
Select-Object DisplayName, AssignedLicenses -ExpandProperty LicenseAssignmentStates
$output = @()
# Loop through all users and get the AssignedByGroup Details which will list the groupId
foreach ($user in $users) {
# Get the group ID if AssignedByGroup is not empty
if ($user.AssignedByGroup -ne $null) {
$groupId = $user.AssignedByGroup
$groupName = Get-MgGroup -GroupId $groupId | Select-Object -ExpandProperty DisplayName
Write-Host "$($user.DisplayName) is assigned by group - $($groupName)" -ErrorAction SilentlyContinue -ForegroundColor Cyan
$result = [pscustomobject]@{
User = $user.DisplayName
Assigned = "Group"
GroupName = $groupName
GroupId = $groupId
}
$output += $result
}
else {
$result = [pscustomobject]@{
User = $user.DisplayName
Assigned = "Direct"
GroupName = "N/A"
GroupId = "N/A"
}
$output += $result
Write-Host "$($user.DisplayName) is direct assigned" -ErrorAction SilentlyContinue -ForegroundColor Yellow
}
}
# Display the results
$output | Export-Csv -Path "C:\temp\LicenseAssignments.csv" -NoTypeInformation -Encoding utf8
$output | Out-GridView -Title "License Assignments"
- Line 58: Edit the CSV file path
Step 3. Run Get-LicenseAssignment PowerShell script
Run the below command to run the script Get-LicenseAssignment.ps1.
c:\scripts\.\Get-LicenseAssignment.ps1
The PowerShell output shows if the license is inherited by a group or is direct assigned.
Note: The output shows if there are multiple groups assigned to a user or if the user has both a license direct assigned and assigned by group. If both are assigned to a user, read the article Remove direct assigned licenses for users with group licenses.
Alison Bell is assigned by group - O365_Licenses_E3_Base
Alison Bell is assigned by group - O365_Licenses_E3_Exchange
Boris Campbell is assigned by group - O365_Licenses_E3_Exchange
Carol Baker is assigned by group - O365_Licenses_E3_Exchange
CloudOnly is direct assigned
Edward Lincoln is assigned by group - O365_Licenses_E3_Exchange
Jeffrey Welch is direct assigned
Jérôme User is direct assigned
Lauren Russell is direct assigned
Phil Peters is direct assigned
Richard Grant is assigned by group - O365_Licenses_E3_Exchange
Richard Grant is direct assigned
Zoë Roberts is direct assigned
Zoë Roberts is assigned by group - O365_Licenses_E3_Exchange
An Out-GridView will show all the information you need.
Step 4. Open license assignment report
The Get-LicenseAssignment.ps1 PowerShell script exports all Microsoft 365 users license assignments to CSV file.
Find the file LicenseAssignments.csv in the path C:\temp.
Open the CSV file with your favorite application. In our example, it’s Microsoft Excel.
The Microsoft 365 user license assignment type report looks great.
Read more: Create Microsoft Entra ID Users from CSV with PowerShell »
Conclusion
You learned how to check if the Microsoft 365 user license is direct assigned or inherited from a group. There are two methods to get the details, which is in Microsoft Entra admin center or with the PowerShell script. Both are excellent to retrieve the information.
Did you enjoy this article? You may also like Export Microsoft 365 inactive users report. Don’t forget to follow us and share this article.
Thanks Ali, I was just looking for something like this. Works perfectly!
Thank you Ali, for the consistency and update you provide. I am always motivated to push more on my Tech career each time I see you post. Great job Man.
Keep pushing, Augustine. You got this!