Assigning O365 licenses in bulk via PowerShell

Continuing from my recent post on How to remove O365 licenses in bulk, I thought it would be a good idea to write about bulk license assignments as well even though its a minor change in the script.

Get the user list in a CSV file. Make sure it includes the User Principal Name or UPN.
In this example, we will be assigning the DEVELOPERPACK_E5 license to the users.

Open up PowerShell and connect to Azure AD using the commandlet Connect-AzureAD. Run the following commands to assign the licenses.

You will need to know the friendly name of the license you want to assign. Check out this post if you need to know how to get the friendly name (SKU Part Number) for the licenses.

$License = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicense
$License.SkuId = (Get-AzureADSubscribedSku | Where-Object -Property SkuPartNumber -Value $planName -EQ).SkuID
$LicensesToAssign = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses
$LicensesToAssign.AddLicenses = $License
$userlist = Import-Csv -Path C:\Temp\userlist.csv
ForEach ($User in $Userlist) {
  Write-Host("Processing: " + $User.UserPrincipalName + ".")
  Set-AzureADUserLicense -ObjectId $User.UserPrincipalName -AssignedLicenses $LicensesToAssign

The output should look like this.

Leave a Reply

Your email address will not be published.