← script library
Monitor Microsoft 365 User Licenses with PowerShell
Microsoft 365 & Entra IDDecember 24, 2024
In this post, we will share a practical PowerShell script to monitor Microsoft 365 user licenses in your organization. Keeping track of user licenses is crucial for effective resource management and cost control. This script will provide you with a detailed overview of the licenses assigned to each user, helping you identify any discrepancies or unused licenses that can be optimized. Here is the PowerShell script to monitor Microsoft 365 user licenses:
powershell
# Connect to Microsoft 365
$credential = Get-Credential
Connect-MsolService -Credential $credential
# Get all users and their license status
$users = Get-MsolUser -All | Select-Object DisplayName, EmailAddress, isLicensed, Licenses
# Generate a report of user licenses
$licenseReport = foreach ($user in $users) {
[PSCustomObject]@{
DisplayName = $user.DisplayName
Email = $user.EmailAddress
IsLicensed = $user.isLicensed
Licenses = ($user.Licenses | ForEach-Object { $_.SkuPartNumber }) -join ", "
}
}
# Output the report
$licenseReport | Format-Table -AutoSize
Write-Host "License report generated successfully."Run it across your fleet
This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.
More in Microsoft 365 & Entra ID
Automate M365 User License Assignment with PowerShell
2025-01-09Manage M365 Users with PowerShell
2025-01-09Automate Microsoft 365 User License Management with PowerShell
2025-01-09Streamlining M365 User Management with PowerShell
2025-01-09PowerShell Script to Retrieve M365 User License Info
2025-01-09Automate Microsoft 365 User Report Generation with PowerShell
2025-01-09Ready when you are.
Try ServerEngine free for 7 days.