This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Set-Msol User License
Updates the license assignment for a user.
The Set-MsolUserLicense cmdlet is deprecated. Learn how to assign licenses with Microsoft Graph PowerShell . For more info, see the Assign License Microsoft Graph API.
Description
The Set-MsolUserLicense cmdlet updates the license assignment for a user. This can include adding a new license, removing a license, updating the license options, or any combination of these actions.
Example 1: Add a license to a user
This command adds the Office 365 for Enterprises license to the user.
Example 2: Remove a license from a user
This command removes the Office 365 for Enterprises license from the user. This may result in the user's data being removed from each service.
Example 3: Replace one license with another
This command replaces the Office 365 for Enterprises license with an Office 365 Deskless license. These changes are made in one single operation. Therefore, the user does not end up in an intermediate state where the Office 365 for Enterprises license is removed without Office 365 Deskless being added.
-AddLicenses
Specifies an array of licenses to assign to the user.
-LicenseOptions
Specifies an array of license- or SKU-specific settings. Used to disable individual services when assigning a license.
Specifies the unique object ID of the user for which to update licenses.
-RemoveLicenses
Specifies an array of licenses to remove from the user.
Specifies the unique ID of the tenant on which to perform the operation. The default value is the tenant of the current user. This parameter applies only to partner users.
-UserPrincipalName
Specifies the user principal name of the user to update.
Related Links
- Set-MsolUserPassword
- Set-MsolUserPrincipalName
Additional resources
Easy365Manager
How to Assign an Office 365 License

To enable the various features of Office 365, you need to assign a license to your user accounts.
The most prominent feature to provision is an Exchange Online mailbox. This is done by assigning an Exchange Online license.
The following sections will show you how to assign (or remove) Office 365 licenses from your users.
Using Easy365Manager to Manage Office 365 Licenses
The easiest way to manage Office 365 licenses is using Easy365Manager .
Easy365Manager is a snap-in to Active Directory Users & Computers that allows you to manage Office 365 licenses (and mailboxes) directly from AD user properties.
With Easy365Manager, you simply open up user properties in AD Users & Computers, select the Office 365 tab and configure your Office 365 licenses:
To try this yourself, download the fully functional 30-day trial.
The installation only takes a few minutes:
Using the Office 365 Web Consoles to Manage Office 365 Licenses
Without Easy365Manager, your user management will be a mixed bag of AD Users & Computers, several Office 365 web consoles, and PowerShell.
Microsoft offers multiple consoles that can be used to manage Office 365 licenses.
The Microsoft 365 Admin Center
To manage Office 365 licenses using the Microsoft 365 Admin Center , select the user account and click on Licenses and Apps:

The Azure AD Portal
Another way to manage Office 365 licenses is using the Azure AD Portal .
Select Users, select a user account, and click on Licenses:

Using PowerShell to Manage Office 365 Licenses
To manage Office 365 licenses using PowerShell, you can use either the MSOnline Module or the Azure AD Module .
Both modules can be downloaded and installed from the PowerShell repository.
To add a license to a user, you need to select the licensing plan and deselect any service plans you want to exclude.
(read this article for a complete overview of Office 365 licenses)
The following sample code will assign the Enterprise Pack license with a few plans disabled.
There are many ways to skin a cat, and the same goes for managing Office 365 licenses.
If you want to make your life easy (or simplify the daily tasks of your helpdesk), take a look at Easy365Manager .
You’ll find a list of features here .
Additionally, Easy365Manager allows you to remove your on-premises Exchange Server , which gives you 100% protection from future zero-day exploits like Hafnium.
Alternatively, you can use a mix of the native Office 365 web consoles or PowerShell for Office 365 settings. At the same time, you must keep in mind that certain properties are authoritative in your on-premises Active Directory.

How to change Office 365 user licenses using PowerShell
The following is a comparison between changing licenses of Office 365 users with Windows PowerShell and ADManager Plus:
Windows PowerShell
Steps to change licenses of office 365 users using powershell:.
- Identify the Office 365 tenant account from which you want to retrieve the report.
- Identify the cmdlets you need for the action.
- Compile the script.
- Execute it in Windows PowerShell.
Sample Windows PowerShell script:
Admanager plus, steps to change licenses for office 365 users:.
- Select Office 365 -> License Management ->Assign/Remove licenses .
- Select Replace licenses option, choose the desired license(s), and User Location from the drop down list.
- Choose the Office 365 account and its users, and click Apply

» Start 30-day Free Trial
Following are the limitations to change licenses of Office 365 users using native tools like Windows PowerShell:
- With additional filters, the script will get longer and more complicated.
- Troubleshooting these scripts requires extensive AD and scripting expertise.
ADManager Plus can help you replace licenses of Office 365 users in a simple and intuitively designed UI.
Assign or remove Office 365 licenses for multiple accounts in one go with ADManager Plus.
- Embark on your script-free AD management, reporting, and automation journey with ADManager Plus.
- By clicking ' Start your free trial now ', you agree to processing of personal data according to the Privacy Policy .
- Your download should begin automatically in 15 seconds. If not, click here to download manually.
Related Powershell How-to Guides:
For AD User Management
- Create new user accounts in AD using Powershell
- Import Active Directory users from CSV using PowerShell
- Add new user in AD using Powershell
- Modify AD user attributes using Powershell
- Enable Active Directory user accounts using PowerShell
- Disable AD accounts using PowerShell
- Delete user accounts in AD using Powershell
- Move AD user accounts using Powershell
- Remove users from Active Directory group using PowerShell
- Set expiration Date for AD Accounts using Powershell
- Modify AD Account Control Values using Powershell
- Unlock AD accounts using Powershell
- Modify AD Objects using Powershell
- Set AD accounts to never expire using Powershell
- Add proxy address to AD user with Powershell Scripts
For AD User Reporting
- Get all AD users report using Powershell
- Get active/inactive AD user accounts using Powershell
- Export enabled AD users report using Powershell
- Get disabled users report in AD using Powershell
- Get active directory account status reports using PowerShell
- Find locked AD user accounts using Powershell
- Find account expired users in AD using Powershell
- Get last logon time of AD user accounts using Powershell
- List AD user accounts set to never expire with Powershell
- Find specific users in AD using Powershell
- Get AD User information with their managers using Powershell
- Get AD user samaccountname using Powershell
- Get AD users' list from multiple OUs using Powershell
- Get AD Users' list along with their Display Names
- Get a list of AD users that belong to a Specific Department
- Get a list of AD users with empty attributes using Powershell
- Get a list of AD Users having a Specific CN using Powershell
For GPO Management
- Create GPO using Powershell
- Create and remove GPO links using PowerShell
- Edit GPO using Powershell
- Generate GPO report using Powershell
- View Unlinked GPO using Powershell
- Get GPOs List using Powershell
- Get GPO Link Report using Powershell
- Backup and restore GPO using Powershell
For Password Management
- Change password for AD users using PowerShell
- Find AD user's last password changed date using PowerShell
- Set password for AD accounts using Powershell
- Set AD user must change password at next logon with PowerShell
- Set AD user password to never expires using Powershell
- Get password expired users list using Powershell
- Get users with soon-to-expire passwords using Powershell
- Get AD Users' List whose passwords never expire using Powershell
- Get Password Expiration Date of AD Users using Powershell
For AD Group Management
- Create Active Directory groups using Powershell
- Add users to Active Directory groups using Powershell
- Add a group as a member of another AD Group using Powershell
- Add principal group membership for AD users using Powershell
- Modify AD group attributes using PowerShell scripts
- Delete Active Directory groups using Powershell
- How to remove a group from another group in AD using PowerShell
- Create dynamic distribution groups using Powershell
- Create distribution groups using Powershell
- Add multiple members to distribution groups using PowerShell
- Group membership report in AD using Powershell
- Get membership details of a specific AD user using Powershell
- Get AD Group members of a specific group using powershell
For File Access Management
- Set and modify folder permissions in Active Directory
- Detect file and folder permissions in AD using Powershell
- Export user's file and folder access permissions using Powershell
- Get permissions of all AD objects using Powershell
- Get ACL for folders and subfolders using Powershell
- Get NTFS permissions using Powershell
For AD Computer Management
- Create AD Computer accounts using PowerShell
- Modify AD Computer attributes using PowerShell
- Enable AD Computer accounts using PowerShell
- Disable AD Computer accounts using PowerShell
- Move AD Computer accounts using Powershell
- Remove AD Computer accounts using PowerShell
- Find inactive AD Computer accounts using PowerShell
- Find AD Computer's last logon time using Powershell
- List Computers in an AD Domain using Powershell
For Office 365 Management
- Guide to Connect to Office 365 Powershell Module
- Add users to Office 365 groups using PowerShell
- Assign license to Office 365 users using PowerShell
- Change Office 365 user licenses using Powershell
- View all Office 365 licenses in your account using Powershell
- Remove Office 365 license from user accounts using Powershell
- Office 365 users license report using Powershell
- Get all Office 365 group members using Powershell
- Dynamic distribution group members report using Powershell
- Dynamic distribution groups report using Powershell
For Exchange Management
- Quick Guide to Connect to Exchange Online PowerShell
- Create Mailboxes in Exchange Online with Powershell
- Remove mailboxes from Exchange Online using Powershell
- Export Exchange Online distribution groups list using PowerShell
- Create Mailboxes in Exchange Servers with Powershell
- Remove user mailboxes from Exchange Server using Powershell
- Export Distribution Group Members Report using PowerShell
For Other AD Tasks
- Guide to install and import PowerShell active directory module
- Sync AD objects using PowerShell
- Add Exchange PowerShell module
- Active Directory Health Check using Powershell
- Active Directory Cleanup using Powershell
- Create OU in Active Directory using Powershell
- Modify OU settings using Powershell
- Get Bitlocker Recovery Keys using PowerShell
- List all Active Directory servers using PowerShell
- Get a list of OUs in AD using PowerShell
- Move AD objects using Powershell
- Search for an AD account using Powershell
- Get AD domain information using Powershell
- Modify an Active Directory domain using PowerShell.
The one-stop solution to Active Directory Management and Reporting
- AD Management
- Exchange Management
- Related Products
- Active Directory Management
- Active Directory Reports
- MS Exchange Management
- Bulk User Management
- Active Directory User Reports
- AD Helpdesk Delegation
- Active Directory Group Management
- AD Logon Reports
- Active Directory Automation
- Active Directory Cleanup
- Distribution List Reports
- ADManager Plus Mobile Apps
- Office365 Management
- Office 365 User Provisioning
- Office 365 Reports
- Bulk User Creation
- Password Management
- Helpdesk Delegation
- Bulk Group Management
- Computer Management
- GPO Management
- Identity orchestration
- User Logon Reports
- AD User Reports
- Password Reports
- Folder Access Reports
- Group Reports
- Computer Reports
- AD Last Logon Reports
- Exchange Reports
- Disable/Delete Exchange Mailbox
- Exchange Mailbox Migration
- Set Mailbox Rights
- Exchange Mailbox Creation
- Office 365 Management
- Office 365 Reporting
- Office 365 License Management
- Office 365 License Reports
- Office 365 User Reports
- Office 365 Group Reports
- Office 365 Automation
- Office 365 Mailbox Management
- Integrated Identity and Access Management Solution
- Unified SIEM Solution
- UBA-driven AD and Windows Server Auditing Solution
- Identity Security Solution with MFA and SSPR
- Real-time Log Management and IT Compliance Solution
- Hybrid Exchange Auditing and Reporting Solution
- File Auditing and Data Leak Prevention Solution
- Microsoft 365 Management and Reporting Solution
- Enterprise Backup and Recovery Solution
- SharePoint Management and Auditing Solution
- Cloud Security and Log Management Solution
- FREE Active Directory Tools
- All Windows Active Directory Solutions
- Download
- Live Demo
- Free Edition
- Get Quote
- Buy Now
Subscribe for Practical 365 updates
Please turn off your ad blocker and refresh the page to subscribe.
You may withdraw your consent at any time. Please visit our Privacy Statement for additional information
Blog / Microsoft Entra ID / PowerShell
Bulk license assignment with the microsoft graph powershell sdk.

Table of Contents
Assigning Licenses to a Bunch of Users
A reader comment for the article covering how to assign licenses to user accounts with the Microsoft Graph PowerShell SDK asked for an example showing how to read accounts from a CSV and assign licenses to those accounts. In other words, how to use PowerShell for bulk assignment of licenses to target user accounts. It’s the kind of thing people do when introducing new products to a tenant.
When Microsoft eventually releases Microsoft 365 Copilot for public consumption, I imagine that organizations willing to stump up the $30/user/month price will look for some sort of bulk assignment mechanism after they decide who gets Copilot licenses . Given that Copilot requires tenants to have Microsoft 365 enterprise licenses, they can use group-based licensing . That’s the best approach and the script discussed here is very much a do-it-yourself assignment mechanism for those who can’t use group-based licensing. Then again, it’s always nice to understand how things work so that you can create your own automation if necessary.
Finding User Accounts to Process
Conceptually, the processing steps are simple. The first step is to import details of target user accounts from a CSV file. Alternatively, you can use another mechanism to establish the set of target accounts. Suitable mechanisms include:
- Membership of a Microsoft 365 group (including dynamic groups). You need to filter the group membership to remove any guest accounts.
- Membership of a distribution list (including dynamic distribution lists). Distribution lists can include objects that can’t be targeted for license assignment, like public folders or mail users, so some filtering is necessary.
- Membership of an Entra ID administrative unit.
- User accounts are found by applying a filter to the Get-MgUser cmdlet .
For example, you could find a set of target accounts by looking for all the accounts located in a certain country:
Of course, using filters to find user accounts only works if account properties are populated with accurate information .
Creating a Target Users Array for Bulk License Assignment
The point is that it doesn’t matter how you generate a set of target accounts. All that’s important is that your script provides a set of identifiers that can be used for license assignment. Those identifiers can be account object identifiers (GUIDs) or user principal names.
For this example, because so many people use CSV files to point to target accounts, that’s what I do in the example script:
The data contained in the $Users array holds the user principal name and display name of the accounts we want to assign licenses to:
Assigning Licenses to Each User Account
The job’s half done when the set of target user accounts is available. After all, the only thing that’s left to do is to run the Set-MgUserLicense cmdlet for each account. Well, that’s certainly true if you want to perform a one-off operation, but it’s best to build some checks and balances in any script code that might be reused.
To illustrate what I mean, examine the processing displayed in Figure 1.

The script:
- Finds the subscribed products (SKUs) known to the tenant and selects the SKUs that still have some available licenses.
- Presents the list of SKUs to the user to allow them to choose which license to assign to the target users.
- Checks that sufficient available licenses exist to assign to all the target users.
- Checks that each target user does not already have the license in their assigned set.
- If the license is not present for a user, attempt to assign the license to the account (note: if your tenant uses restricted administrative units , only accounts holding administrator roles for the administrative units can assign licenses to member accounts).
- Captures details of the success or failure of the license assignment and records the information in a list object (Figure 2).
- Reports details of the processing, including how many successful and failed license assignments occurred.


The Microsoft 365 Kill Chain and Attack Path Management
An effective cybersecurity strategy requires a clear and comprehensive understanding of how attacks unfold. Read this whitepaper to get the expert insight you need to defend your organization!
More Improvements Possible
I spent a happy afternoon playing with the script to anticipate some of the situations that you might encounter during license assignment operations, but I think I barely scratched the surface. There is much more that could be done to expand the script to handle different conditions, such as:
- Assigning multiple product SKUs at one time.
- Disabling service plans that the organization doesn’t want people to use from product SKUs. For instance, the organization might decide that Viva Engage (Yammer) isn’t required and therefore disables the Viva Engage Core service plan in SKUs like Office 365 E3 and E5. That’s possible, but if you disable Viva Engage, you lose some Teams functionality, like the Q&A app in meetings.
- Share the results of the license assignment processing with other people via email or Teams.
Please feel free to amend the script I wrote ( available for download from GitHub ) to add your ideas. I might disagree with your suggestions, but at least we can have a discussion.
Bulk License Assignment Automated Your Way
PowerShell makes it possible to automate operations the way you want things done rather than the way Microsoft thinks things should be done. That’s its big advantage and it’s the core reason why every Microsoft 365 administrator should be passingly fluent in PowerShell.
If you attend The Experts Conference in Atlant a (Sept 19-20, 2023), make sure to come to the Great PowerShell Script-Off to have some fun and support the contestants as they struggle with the challenges we’ll set for them. All the challenges are common Microsoft 365 tenant automation tasks, so you might even learn something too!
About the Author

Tony Redmond
Hi Tony, I work in a school enviornment and the students are assigned with one the below license. I want to disable the Teams license from the students account listed in a csv file. I have to enable the Teams license later. Students UserPrincipalName are saved in this location: C:\Data\StudentsToDisable.CSV
Please help me with the powershell script
‘M365EDU_A5_STUUSEBNFT’ ‘ENTERPRISEPACKPLUS_STUDENT’ ‘STANDARDWOFFPACK_STUDENT’ ‘M365EDU_A3_STUUSEBNFT’ ‘STANDARDWOFFPACK_IW_STUDENT’
There are many script examples that are available on the internet that you can use as a basis. You don’t say how you know which license to assign to an account. Assuming that this information is in the CSV file, I would:
• Connect to the Graph with Connect-MgGraph. Make sure that the scope set is User.ReadWrite.All. • Import the user data from the CSV file with Import-CSV. • For each user, run Set-MgUserLicense to assign the license and disable the Teams service plan (57ff2da0-773e-42df-b2af-ffb7a2317929). Make sure that you know the GUID for each product license you plan to use, like 31d57bc7-3a05-4867-ab53-97a17835a411 for M365EDU_A5_STUUSEBNFT.
Product GUIDs are available from https://learn.microsoft.com/en-us/entra/identity/users/licensing-service-plan-reference .
I keep getting this error. I ran it with just changing the filename to mine & even tried the snippet above. Same error
WARNING: One or more headers were not specified. Default names starting with “H” have been used in place of any missing headers.
Cannot index into a null array. At line:76 char:5 + Write-Host (“{0} users are to receive licenses but there are only … + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : NullArray
Looks like the Import-CSV from the file pointed to with $InputFile didn’t bring in any user accounts to process.
Hi Tony, thank you for the very intersting script. I’m trying to use only a part of it as my task is a one shot group add of licences, but I am stuck with an error. Here is the script I adapted: $InputFile = “c:\Users\damien.hartmann\Documents\comptes.csv” [array]$Users = Import-CSV $InputFile ForEach ($User in $Users) { $License = Set-MgUserLicense -UserId $User.UPN -Addlicenses @{SkuId = ‘$18181a46-0d4e-45cd-891e-60aabd171b4e’} } Would you by chance see where I made a mistake?
Your SKUID has a $ sign in the first character. That makes it an invalid GUID
Thanks, but I still get the same error message: Set-MgUserLicense : Impossible de lier l’argument au paramètre « UserId », car il s’agit d’une chaîne vide. Au caractère C:\Users\damien.hartmann\Documents\WindowsPowerShell\ajouter_licences_v3.ps1:3 : 66 + … r in $Users) { $License = Set-MgUserLicense -UserId $User.UPN -Addlic … + ~~~~~~~~~ + CategoryInfo : InvalidData : (:) [Set-MgUserLicense], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Set-MgUserLicense (sorry for the French)
Finally I managed to make it work, thanks again!
Hey can you send me the code you used
Hi Tony, I found the script, whoch is working fine for me. Thank you
Hi Tony, The arcticle is elaborate an dvery helpfull, please share the Script that does the output shown in powershell above
The script is available in GitHub and is linked to in the article.
Leave a Reply Cancel reply
Latest articles.

Practical Protection: Top Ten Cybersecurity Mistakes the NSA Thinks You’re Making
The NSA and CISA released a joint bulletin titled “Top Ten Cybersecurity Misconfigurations.” In this blog, Paul Robichaux reviews a few of the most significant suggested mitigations from this bulletin.

How to Remove Obsolete Holds from SharePoint Sites and Exchange Mailboxes
The Invoke-HoldRemovalAction cmdlet is available in the compliance module. Its role is to remove obsolete eDiscovery holds from Exchange Online mailboxes and SharePoint Online sites. Old, lingering holds can prevent the removal of objects, so it's good to get rid of them.

Signing into a Windows Device Using the Web
In this blog, Thijs Lecomte reviews the new Web Sign-in feature for Windows 11 and its specific use cases.
- Microsoft 365

- PowerShell Gallery
- Guest articles
- Technet Links
- Privacy Policy
- Speaker Profile
- Speaker Booking
- Teams Concierge
Assign licenses to users in Office 365 for business
We have a new employee in our company, who starts his work as junior System Engineer. However, as a junior there are still many things to learn and I am also responsible to show him some things from the Microsoft Exchange and Office 365 world. Honestly saying, I like the new Guy, he is motivated and he asks questions about things he don’t know.
From my point of view this two skills (being motivated and not being scared to ask questions) are a good for start and to become a good Engineer in the future.
Some days ago, he asked me how to assign licenses to users in Office 365. To show that was not a big deal. However, in the evening by driving home from work, I came to the idea to write a short article about that. Not just how to enable a license for one user, also different ways how this can be done for multiple or by using other ways like PowerShell.
Assign license for one user, using Office 365 admin center
After logging in to the Office 365 admin center, we browse to Users > Active users and here we search for the user, we want to assign a license.
In the tab Product licenses we chose the option Edit .
As we can see in the picture below, (and depends about our subscriptions). We simply switch the toggle to On position for the license that we want to assign to this user.

Note : By default, all services associated with that license are automatically assigned to the user. To limit services, which are available to the user, switch the toggles to the Off position for the services that you don’t want that user has.
To finish this operation of assigning the license we need to scroll down to the bottom of the Product license pane and there we have to choose Save . If everything is fine this will be successful, and we can close the window. If we get an error here, we can check two points:
- Are there enough licenses available?
- Do we have set the user Location on the top?
Assign license for multiple users
For assigning license to multiple users we can follow the steps like by a single user. However, there is just a little difference to the steps by a single user…
First, we need to log-in to our Office 365 admin center, after that we browse to Users > Active users and here we search for all the users, we want to assign a license.
After selecting at least, a second user, we get a new popup window on the right site of our web browser, which is called Bulk actions.

As we can see, here we have now multiple options to continue our work. In our scenario we want to assign an Office 365 license to multiple users, in this case we need now to choose the option Edit product licenses.

Now we can assign the necessary licenses to the selected users.
Enable license using PowerShell
Another way to assign licenses to the users in our company is with using PowerShell.
The first thing we have to do is to connect to our Office 365 Tenant by using PowerShell. To do that, we need following commands:
Note : if you haven’t installed the MSOnline Module, you can do that by running your PowerShell with Administrative rights and hitting the following cmdlet:
To be able to assign licenses by PowerShell, we need now to know the User Principal Name (UPN) of the user we want to assign the license. However, as well we need to know which license we want to assign. For an easier understanding you can have a look on the following example:
So, how to know how the licenses are called in the PowerShell and how to find out how many freelicenses we still have? This we can figure out easily by using the following command:
Here is an example, how the output could look like:

Here we see the exact name and a number of Active and Consumed Units.
To get a list of all our users which has no license assigned, we can hit this command:
This command can help us for assigning licenses for multiple users. As example the command could look like this:
If we don’t want to do that for the whole company, we also can do it for departments, then the command could look like this:
What we need to know about assigning licenses to users in Office 365
There are some things which are good to know about assigning licenses to our users:
- We need to be either a Global administrator or at least a User management administrator in our Office 365 Tenant.
- Some services, like Sway, are automatically assigned to users, and don’t need to be assigned individually.
In German we have an expression: “Viele Wege führen nach Rom”. That means, there are many ways how we can make sure that the users from our company has the right license assigned. The most common ones I have just showed here in this article. However, there are other ways as well. Just one of the examples: We can create Azure Active Directory groups-based licensing where we can add our users and then the licenses will be assigned automatically. If you are interested in this, I can recommend you the official Microsoft doc following the Link HERE .
I guess the most of you knew at least one of the options I have shown in this article, from my point of view we need to take time and support our motivated junior Engineers by helping them going very first steps in the Office 365 and Azure world.
Photo by Steve Johnson on Unsplash
Leave a Reply Cancel reply
You must be logged in to post a comment.

COPYRIGHT © 2023 | dotCLOUD Consulting Ltd. All Rights Reserved.
Privacy Overview
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:
- Install and Import Exchange Online Powershell Module
- Connect to Exchange Online ( EXO )
- Connect to Entra ID
- Export a list of users with their UPN information.
- 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]
- 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.
- Assign Microsoft Entra ID P1 to a User using below PowerShell command.
- 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.
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.
- 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.

Leave a Comment Cancel reply
Save my name, email, and website in this browser for the next time I comment.
Notify me of follow-up comments by email.
Notify me of new posts by email.

Detailed Step-by-Step guides for Setup/Troubleshooting/Configuration solutions on Intune, Microsoft 365, Powershell, Windows, Azure, and other Cloud technologies.
About the author Contact Us Privacy Policies Comment Policies Cookie Policies
Let's Connect!
Email Address

Erwin Bierens

Microsoft 365 - Assign licenses with PowerShell to users
During the working week i get a lot of questions about assigning licenses (mostly the Microsoft Teams Phone Standard license) to users in bulk. This can be easily resolved with PowerShell.
First logon to MSOnline, if you don’t have this module installed use: Install-Module -name MSOnline
Let’s see your active licenses
In order to assign a license to one of your users use the following cmdlet
In this example we’ve assigned the Microsoft Teams Phone Standard license to the user.
If you want to do this for multiple accounts you can do this by creating a script. First create a csv file with a column header: UPN List all accounts below with the UPN address who will need the license.
Save script below as Set-SKULicense.ps1 and change the $FilePath to the correct filename. Now just run the file and copy/paste the license in the prompt you want to assign.
- Infra as Code
- Microsoft 365

Assigning Office 365 license via PowerShell is the need of the hour if the tenant doesn’t have a p1 license and you got to apply them manually. the only easy way is to use PowerShell for bulk license assignment. Also, it’s useful to upgrade or renew different licensing.
if you don’t have the module

Got the usage location as US

use the below command to Cross-checking on applied values – or use GUI

Now usage location is updated on the required accounts. as it’s mandatory before assigning a license via PowerShell. in my case, I don’t have a p1 license in this tenant that’s the reason I got to do this via PowerShell otherwise I would use dynamic licensing
In my case, I need to assign ExchangeStandard

once you have a proper value assigned on this variable $LicensesToAssign you can use import-csv to assign all users.
Now you can see licenses got assigned successfully.

Related Articles
Deploy next.js app on azure app service with azure devops pipelines, deploy a container image in a linux vm, configure azure app service deployment slot.
Hi , Is there a way to know one specific DL is added to how many DL’s via your script ?
Thanks in advance
if it’s an on-premises DL. member of will help in this case
LEAVE A REPLY Cancel reply
Save my name, email, and website in this browser for the next time I comment.
EDITOR PICKS
Popular posts, popular category.
- x-All Posts-x 640
- Exchange 2013 183
- Microsoft 365 123
- Exchange 2010 122
- Exchange 2016 105
- Azure Active Directory 100
- Windows Server 55

Build Office 365 License Options Using PowerShell – Part 2
Azure active directory licensing.
Microsoft has made significant strides with licensing options for Office 365. Licensing options can be found in the new Active Directory snap-in within Azure. This new snap-in allows organizations to control both licensing options and their associated services.
The Azure Active Directory snap-in can be accessed by following these steps:
- Login to https://portal.azure.com

More information on Azure Active Directory licensing in Azure can be found in the articles below.
https://docs.microsoft.com/en-us/azure/active-directory/active-directory-licensing-what-is
https://channel9.msdn.com/Series/Azure-Active-Directory-Videos-Demos/How-to-assign-Azure-AD-Premium-Licenses-to-user-accounts
https://docs.microsoft.com/en-us/azure/active-directory/active-directory-licensing-group-assignment-azure-portal
https://docs.microsoft.com/en-us/azure/active-directory/active-directory-licensing-group-migration-azure-portal
Why do you need an Office 365 licensing script? The answer is twofold. First, the Office 365 license script is a set-it and forget-it tool. Any new service that is added to Office 365–and Microsoft is always adding new services–will be set to a disabled state for all users automatically the next time the script is executed. So, no interaction is needed from an administrative perspective.
Secondly, the Azure Active Directory snap-in does nothing for directly assigned licenses. Directly assigned licensing refers to administrators setting the license directly on a user, or group of users.
Our recommendation is to use the Office 365 licensing script along with the licensing option in Azure Active Directory. The Office 365 licensing script is part of the licensing solution. In many cases, Azure Active Directory will meet roughly 90% of your organization’s licensing needs. The Office 365 licensing script should fulfill the remaining 10%.
To illustrate how the Office 365 licensing script can support licensing features in Azure Active Directory, lets continue with the example above. I went into Janet’s account and directly assigned all services under E3 licenses to Janet’s account.
Note : You cannot disable any services that are assigned through licensing policies; you can only add new services.

The best way to set Janet’s account back to the deployed licensing option is via the Office 365 licensing script. Once the script has finished executing, licensing options will be set back for Janet’s account.

When configuring the licensing script to work within your organization, it is important to put the most restrictive AD group first in the script. By putting the most restrictive AD group first, if a user is a member of multiple security groups, that user would be assigned less restrictive licenses.
The following are requirements to run the Office 365 licensing script:
- The path C:\temp\services\logs , needs to be created on the computer running the script
- The first time running the script it will ask for the admin password. Once the password is provided, it will store the password in a secure file
- The username needs to be changed to the admin account on line 3
- Modify license information on lines 70 – 74
- If you want to enable any other services, update line 10
- To modify groups, edit lines 21 & 22 . Groups should be those that are assigned licensing options within Azure Active Directory
- The script will create a log file under C:\temp\services\Logs
- The computer \ server must have the AD module installed
Note: If you want to use cloud groups instead of AD groups or want to use the Azure AD version of an AD group, please see Part 1 of the Office 365 licensing blog.
Current Licensing options for E3 as of 3/8/2017
- FLOW_O365_P2
- PROJECTWORKMANAGEMENT
- INTUNE_O365
- YAMMER_ENTERPRISE
- RMS_S_ENTERPRISE
- MCOSTANDARD
- EXCHANGE_S_ENTERPRISE
- OFFICESUBSCRIPTION
- SHAREPOINTWAC
- SHAREPOINTENTERPRISE
- POWERAPPS_O365_P2
Two Groups created within Active Directory. Each group only has one member, Christopher Crandall.

Since Christopher is a member of two groups, we want to place the most restrictive group first in the script. In our script, the E3-Limited group would be listed first.
The only services that should be enabled for Christopher’s account are Office Online, SharePoint, and PowerApps. The enabled apps can be changed by editing the service names listed in the code snip-it below.

Christopher’s account currently does not have any assigned licenses within Office 365.

Once the script is finished, Christopher will have EMS and limited services within E3.

From the log file, all the other Office 365 services have been set to a disabled state.


IMAGES
VIDEO
COMMENTS
Did you know that you can get the most out of Microsoft Office 365 by using it from anywhere in the world? All you need is an internet connection. You can access your Office 365 account from anywhere in the world as long as you have an inte...
As a student, you’ll likely have many times when you turn to Microsoft Office software to complete school assignments and projects. The good news is that Microsoft offers its Office 365 subscription plan free to students and educators in th...
Do you want to get the most out of Microsoft Office 365? Then check out our five-point guide! In this guide, we’ll show you how to get started with Office 365 and make the most of its features.
Use the Microsoft Graph PowerShell SDK. First, connect to your Microsoft 365 tenant. Assigning and removing licenses for a user requires the
This command adds the Office 365 for Enterprises license to the user. Example 2: Remove a license from a user. PowerShell. Copy.
To manage Office 365 licenses using PowerShell, you can use either the MSOnline Module or the Azure AD Module. Both modules can be downloaded and installed from
Steps to change licenses for Office 365 users: · Select Office 365 -> License Management ->Assign/Remove licenses . · Select Replace licenses option, choose the
Alternatively, you can use another mechanism to establish the set of target accounts. Suitable mechanisms include: Membership of a Microsoft 365
Not just how to enable a license for one user, also different ways how this can be done for multiple or by using other ways like PowerShell. Assign license for
Assign licenses to List of Users (Synced or In-Cloud) in a Text File using Powershell on Office365. Use Set-MsoluserLicense to configure.
Bulk mode. If you want to do this for multiple accounts you can do this by creating a script. First create a csv file with a column header: UPN
The goal is to assign multiple licenses to users. For example, I need to assign O365 E3 + AAD P1 + MDO P2 to 300 users. Then another assignment
Assigning Office 365 license via PowerShell is the need of the hour if the tenant doesn't have a p1 license and you got to apply them manually.
Select Azure Active Directory · Under Manage, select Licenses · Under Manage, select All products · Select a license and click Assign · Under Users and groups