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.
Categories: Microsoft 365, Microsoft Azure, PowerShell