← script library

Automate Office 365 License Assignment with PowerShell

Microsoft 365 & Entra IDDecember 24, 2024

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:

powershell
# 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.

Ready when you are.

Try ServerEngine free for 7 days.