Assign License to Microsoft 365 users using Powershell

To ensure that users can access Microsoft 365 services, it’s required to assign a relevant license, whether they are provisioned through Entra ID Connect or directly on Microsoft 365.

After a user account has been created on Microsoft 365, you can allocate the license, for example: Microsoft 365 E3 or Microsoft 365 Business Premium, based on the Microsoft 365 license subscription purchased.

Once a license has been assigned, resources will be provisioned in the background for the user. For example, An Exchange Online mailbox, OneDrive, etc.

Assign Microsoft 365 License using Powershell

Please follow below steps to assign a Microsoft 365 license to the user using Powershell:

  1. Install and Import Exchange Online Powershell Module
1. Install-Module -Name ExchangeOnlineManagement

2. Import-Module ExchangeOnlineManagement
  1. Connect to Exchange Online (EXO)
Connect-ExchangeOnline -UserPrincipalName <UPN>
  1. Connect to Entra ID
connect-msolservice
  1. Export a list of users with their UPN information.
Get-msoluser | select Userprincipalname | out-file c:\temp\userprincipalname.txt
  1. Then filter the list to find which users need to be assigned the licenses. Copy those users in a separate notepad. userprincipalname.txt file should only contain the UPNs e.g. as shown below

Userprincipalname.txt

[email protected]
[email protected]
[email protected]

  1. Using the Product names and service plan identifiers page, Find out which license needs to be assigned to the users. Note down the license String ID.

For Example:

For Microsoft Entra ID P1, the String ID is AAD_Premium. We will use it to assign this license using Powershell.

  1. Assign Microsoft Entra ID P1 to a User using below PowerShell command.
Set-MsolUserLicense -UserPrincipalName [email protected] -AddLicenses "AAD_PREMIUM"
  1. Assign Microsoft Entra ID P1 to bulk users. You can add UPNs of the users in a file called userprincipalname.txt and store it in C:\temp. Then run below powershell script to assign Microsoft Entra ID P1 to all those users.
$users = Get-Content c:\temp\userprincipalname.txt
foreach($user in $users)
{
Write-host "Setting AAD Premium on '$user'" -ForegroundColor Black -BackgroundColor Green
Set-MsolUserLicense -UserPrincipalName $user -AddLicenses "AAD_PREMIUM"
}

How to assign License from Microsoft 365 admin center?

You can follow below steps to assign Microsoft 365 license to the users from admin center.

  1. Login on Microsoft 365 admin center
  2. Click on Users > Active Users
  3. Click on any user > Click on Licenses and apps.
  4. Use the checkbox next to the license to assign a license.
How to assign License from Microsoft 365 admin center?
How to assign License from Microsoft 365 admin center?

Leave a Comment

Discover more from TechPress

Subscribe now to keep reading and get access to the full archive.

Continue reading