TinyAddicts is a series of ultra-short, ultra-useful scripts and snippets. No fluff – just pure, working code. Perfect for admins, devs, and anyone who values their time.
Scenario
Need to find users who exist in Entra ID but don’t have any Microsoft 365 licenses assigned? These accounts might be test users, onboarding leftovers, or simply inactive. Here’s a reliable one-liner to list them.
Code
|
1 2 3 |
Get-MgUser -All -Property DisplayName,UserPrincipalName,AssignedLicenses | Where-Object { $_.AssignedLicenses -eq $null -or $_.AssignedLicenses.Count -eq 0 } | Select DisplayName, UserPrincipalName |
Sample output
|
1 2 3 4 |
DisplayName UserPrincipalName ------------ ------------------- Test Account test1@contoso.com Old User old.user@contoso.com |
Notes
- Requires
User.Read.AllorDirectory.Read.Allpermission. - Works reliably without relying on unsupported Graph filters like
assignedLicenses/$count. - Great for license cleanup, onboarding checks, or catching missed assignments.
- You can also export the list to CSV:
|
1 |
... | Export-Csv ".\UnlicensedUsers.csv" -NoTypeInformation -Encoding UTF8 |
More bite-sized scripts in the TinyAddicts series – simple tools, serious impact.

