Microsoft 365

Azure AD: Assign License to multiple Users (Bulk)

In this blog post I will carry out how to assign licenses to multiple users, no matter if you want to assign licenses to 5 or 5000 users. In order to use full functionality of Azure AD and its related services, users need to be assigned a license. Let’s dive in.

Prerequisites

Connect to and/or install AzureAD.

Install-Module AzureAD -AllowClobber -Force # optional
Connect-AzureAD

First, make sure your users have assigned a location.

Get-AzureADUser | Select-Object DisplayName,ObjectId,UsageLocation

If not, assign a usage location with this code sample for AT = Austria.

$allusers = Get-AzureADUser 

foreach ($a in $allusers) {                             

    Set-AzureADUser -ObjectId $a.ObjectId -UsageLocation "AT" 

}

Assign License to multiple (all) Users

First, find out your plan name to assign.

Get-AzureADSubscribedSku  

In my case, it is the ENTERPRISEPACK. Provide this name in line 2 of the code below.

$license = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicense 
$planname = "EnterprisePack"
$licenseadd = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses
$License.SkuId = (Get-AzureADSubscribedSku | Where-Object -Property SkuPartNumber -Value $planName -EQ).SkuID
$licenseadd.AddLicenses = $license

$allusers = Get-AzureADUser 

foreach ($i in $allusers) {                            
    
    Set-AzureADUserLicense `
    -ObjectId $i.ObjectId `
    -AssignedLicenses $licenseadd 
}

Now you have successfully assigned a license to all Azure AD users.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.