Listen to this Post
Managing Microsoft 365 licenses can be deceptively complex, involving reporting, bulk assignments, and optimizations. AdminDroid has developed a PowerShell script to simplify these tasks, covering over 10+ operations in a single script.
๐ Download the script here: https://lnkd.in/dcAg4kAY
You Should Know: PowerShell Commands for Microsoft 365 License Management
1. Connect to Microsoft 365
Before running any license management commands, connect to Microsoft 365 using PowerShell:
Install-Module -Name MSOnline -Force Connect-MsolService
2. Get All Licensed Users
List all users with assigned licenses:
Get-MsolUser | Where-Object { $_.IsLicensed -eq $true } | Select-Object UserPrincipalName, Licenses
3. Assign Licenses in Bulk
Assign a license to multiple users from a CSV file:
$Users = Import-Csv -Path "C:\Users.csv"
foreach ($User in $Users) {
Set-MsolUserLicense -UserPrincipalName $User.UPN -AddLicenses "tenant:ENTERPRISEPACK"
}
4. Remove Licenses from Inactive Users
Find and remove licenses from users who havenโt logged in for 30+ days:
$InactiveUsers = Get-MsolUser -All | Where-Object { $_.LastLogonTime -lt (Get-Date).AddDays(-30) }
foreach ($User in $InactiveUsers) {
Set-MsolUserLicense -UserPrincipalName $User.UserPrincipalName -RemoveLicenses $User.Licenses.AccountSkuId
}
5. Generate a License Usage Report
Export a detailed license report to a CSV file:
Get-MsolAccountSku | Select-Object AccountSkuId, ActiveUnits, ConsumedUnits | Export-Csv -Path "C:\LicenseReport.csv" -NoTypeInformation
6. Check Available Licenses
View remaining available licenses:
Get-MsolAccountSku | Format-Table AccountSkuId, ActiveUnits, ConsumedUnits, @{Name="Remaining"; Expression={$<em>.ActiveUnits - $</em>.ConsumedUnits}}
What Undercode Say
Automating Microsoft 365 license management with PowerShell saves time and reduces human error. The provided script by AdminDroid consolidates multiple tasks, making it ideal for IT admins managing large environments.
Additional Useful Commands
- List all Microsoft 365 SKUs:
Get-MsolAccountSku
- Disable a userโs license without deleting their account:
Set-MsolUserLicense -UserPrincipalName "[email protected]" -RemoveLicenses "tenant:ENTERPRISEPACK"
- Reassign a license to a different user:
Set-MsolUserLicense -UserPrincipalName "[email protected]" -RemoveLicenses "tenant:ENTERPRISEPACK" Set-MsolUserLicense -UserPrincipalName "[email protected]" -AddLicenses "tenant:ENTERPRISEPACK"
For Linux admins, similar automation can be achieved using Azure CLI:
az login
az account list --output table
az ad user list --query "[?assignedLicenses!='null'].{UPN:userPrincipalName, Licenses:assignedLicenses}"
Expected Output:
A streamlined PowerShell automation script for Microsoft 365 license management, reducing manual workload and improving efficiency.
๐ Script Download: https://lnkd.in/dcAg4kAY
References:
Reported By: Jake Admindroid – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass โ



