Whether users are provisioned via Azure AD Connect Sync or directly on office 365 cloud (In-Cloud Users). We need to assign the licenses to users to get certain features and functionality. For working with Exchange Online, Once you have sync’ed the user to office365, you can assign appropriate license (e.g. Office 365 E3 or office 365 Business Premium etc.) depending upon the plan you purchased from Microsoft to get their mailbox created in Exchange Online.
Read More: Powershell – Export the list of users and assigned licenses from Microsoft 365
How to assign Office 365 Licenses using Powershell
Please follow below steps to assign an Office 365 / Microsoft 365 license to the user:
- Connect to Exchange Online (EXO)
$mycred = Get-Credential <Global Administrator User ID>
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $mycred -Authentication Basic -AllowRedirection
Import-PSSession $Session
- Connect to Azure Active Directory (Azure AD)
connect-msolservice
- Capture the
UserPrincipalname
of all the users in a variable or export it to a file calleduserprincipalname.txt
. I will recommend to export it to a txt file and filter the list to see which users needs to be assigned licenses.
$users = Get-msoluser | Select Userprincipalname
OR
Get-msoluser | select Userprincipalname | out-file c:\temp\userprincipalname.txt
The userprincipalname.txt file should only contain the UPNs e.g. as shown below
Userprincipalname.txt
user1@techpress.net
user2@techpress.net
user3@techpress.net
- Find out which license needs to be assigned to the user using link Microsoft Licensing Service Plan Reference
For example: AAD_PREMIUM (Azure Active Directory Premium P1) therefore I used AAD_Premium in the below script to add the license to the users. I will recommend to run the command on one or two users first and check it on office365 if the license has been assigned successfully. Once its successful, you can just add the UPNs of the users in a text file and run it using foreach loop in powershell using below code.
- Assign /Add AAD_PREMIUM license to one user
Set-MsolUserLicense -UserPrincipalName user1@techpress.net -AddLicenses "AAD_PREMIUM"
- Assign/Add AAD_PREMIUM License to list of users mentioned in text file called userprincipalname.txt
$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 Office 365 License from Microsoft 365 admin center
You can follow below steps to assign Office 365 license to the users:
- Login on Microsoft 365 admin center
- Click on Users -> Active Users
- Click on any user -> Click on Licenses and apps.
- Use the checkbox next to the license to assign a license.

Conclusion
In this blog post, we have seen how to add / assign an office 365 license to users by using Microsoft 365 admin center and also using Powershell.