Automate Office 365 License Assignment with PowerShell
In this post, we will introduce a PowerShell script that automates the assignment of Office 365 licenses to users in your organization. Managing licenses efficiently is crucial for ensuring that employees have access to the necessary resources for their roles. This script allows administrators to assign licenses in bulk, simplifying the user onboarding process and ensuring compliance with your organization's licensing agreements. Here is the PowerShell script for automating Office 365 license assignments:
# Connect to Microsoft 365
$credential = Get-Credential
Connect-MsolService -Credential $credential
# Define user details and license SKU
$usersToLicense = @("[email protected]", "[email protected]") # List of users to assign licenses
$licenseSku = "yourtenant:ENTERPRISEPACK" # Replace with your actual license SKU
# Assign licenses to each user
foreach ($user in $usersToLicense) {
Set-MsolUserLicense -UserPrincipalName $user -AddLicenses $licenseSku
Write-Host "Assigned license to $user 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.