Powershell: Applying Licenses to list of users on Office365

Summary: Whether the users are provisioned via Azure AD Connect Sync or directly on office365 cloud (In-Cloud Users). We need to allocate and assign the licenses to the users to get certain features and functionality enabled for them. e.g. 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 office365 Business Premium etc.) depending upon the plan you purchased from Microsoft to get their mailbox created in Exchange Online.

You can assign the licenses via GUI or using Powershell as shown below:

GUI Method

Assign a license using GUI is simple:

  • just Select the user on office365 -> go to Product Licenses and click Edit.
  • Configure the users location and Toggle the Switches next to licenses to switch it ON or OFF (if you are unable to allocate the license to a user, it could be that the license has not been allocated or available)

Powershell Method

Assign a license to the users using Powershell:

  • Connect to Exchange Online (EXO)
  • Connect to Azure Active Directory (Azure AD)
  • Capture the UserPrincipalname of all the users in a variable or export it to a file called userprincipalname.txt. I will recommend to export it to a txt file and filter the list to see which users needs to be assigned licenses.

OR

The userprincipalname.txt file should only contain the UPNs e.g. as shown below

Userprincipalname.txt

user1@technethub.com
user2@technethub.com
user3@technethub.com

e.g. in my case it was 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. Then once you are confident, you can just copy 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 
  • Assign/Add AAD_PREMIUM License to list of users mentioned in text file called userprincipalname.txt

References:

To Export the list of Office365 users with their Assigned Licenses you can follow below link:

Powershell: Export the list of users and licenses assigned to them from Office 365

1 thought on “Powershell: Applying Licenses to list of users on Office365”

Leave a Reply

Your email address will not be published. Required fields are marked *

error:
%d bloggers like this: