Scripts & PS
How to Export M365 Licence Reports with PowerShell
Published 16 January 2026
·
6 min read
Knowing what Microsoft 365 licences are assigned, which users have licences they do not need, and how many remain is important for cost management. This guide covers pulling licence data via Microsoft.Graph PowerShell and exporting to CSV.
Connect and view licences
Connect-MgGraph -Scopes "User.Read.All","Organization.Read.All"
# View tenant licence overview
Get-MgSubscribedSku | Select SkuPartNumber, ConsumedUnits, @{N="Available";E={$_.PrepaidUnits.Enabled - $_.ConsumedUnits}}Per-user licence report
$allUsers = Get-MgUser -All -Property DisplayName,UserPrincipalName,AssignedLicenses,Department
$skuMap = @{}
Get-MgSubscribedSku | ForEach-Object { $skuMap[$_.SkuId] = $_.SkuPartNumber }
$report = $allUsers | ForEach-Object {
[PSCustomObject]@{
DisplayName = $_.DisplayName
UPN = $_.UserPrincipalName
Department = $_.Department
Licences = ($_.AssignedLicenses | ForEach-Object { $skuMap[$_.SkuId] }) -join ", "
LicenceCount = $_.AssignedLicenses.Count
}
}
$report | Format-Table -AutoSizeFind unlicensed users
# Users with NO licences
$report | Where-Object { $_.LicenceCount -eq 0 } | Select DisplayName, UPN, Department
# Users with more than one licence
$report | Where-Object { $_.LicenceCount -gt 1 } | Select DisplayName, UPN, LicencesExport to CSV
$report | Export-Csv -Path "C:\Temp\M365-Licences-$(Get-Date -Format yyyyMMdd).csv" -NoTypeInformation -Encoding UTF8
Frequently Asked Questions
Q: How do I find users who have not signed in for 90 days?
Add SignInActivity to your user query. Filter where LastSignInDateTime is older than 90 days. Requires Entra ID P1/P2.
Q: Can I remove licences in bulk?
Yes. Use Set-MgUserLicense -RemoveLicenses with an array of SkuIds. Always test on a pilot user first.
Q: What is the difference between SkuPartNumber and SKU ID?
SkuPartNumber is human-readable (e.g. SPB for Business Premium). SkuId is the GUID used in API calls.