The smarter way to manage Microsoft 365. Try AdminDroid for free!
How to Manage User Licenses Using Microsoft Entra PowerShell

How to Manage User Licenses Using Microsoft Entra PowerShell

Managing Microsoft 365 licenses means quickly identifying which users need which licenses and removing any that are no longer required. With the retirement of the MSOnline module, modern alternatives like Microsoft Graph API and Microsoft Graph PowerShell have become the preferred tools for admins. However, Graph PowerShell can be complex for common license management tasks, requiring multiple commands and deeper knowledge of Graph endpoints.

Microsoft Entra PowerShell addresses these challenges by providing a simpler, more intuitive way to manage licenses, users, groups, and applications. In this blog, we’ll explore how to manage user licenses using Entra PowerShell effectively to optimize license usage and cut down unwanted costs.

Prerequisites for Managing User Licenses Using Entra PowerShell

Before diving into managing user licenses with Microsoft Entra PowerShell, make sure that the following prerequisites are in place:

  • Module: Install the Microsoft Entra PowerShell module, if it’s not already available.
  • Role requirement: You must have the License Administrator role or a higher privileged role assigned.
  • Microsoft Graph API Permissions: Connect to the Entra PowerShell with the scopes User.ReadWrite.All and Organization.Read.All.
  • Assign usage location to users: Since certain Microsoft services are not available in some region, make sure that your users have been assigned a usage location. Without this, license assignments for region-specific services may fail. You can identify users without a usage location using the following cmdlet:

    After identifying users without a defined location, assign each user an appropriate usage location using the following command.

    Replace <UserPrincipalName> with the user’s principal name and <UsageLocation> with the correct code of the country or region, such as IN for India, US for the United States, etc. This method is convenient when updating the location for a few users.

    However, to assign usage locations to multiple users at once, you can create a CSV file containing the UserPrincipalName and UsageLocation columns, as shown in the sample below. Make sure to use the same column names in both the CSV file and the script to avoid errors during execution.

    bulk-update-usage-location-csv-inputSave the created file and run the following PowerShell snippet to assign the usage locations to all users in the CSV.

    Replace <FilePath> with the CSV file’s path to automatically set the usage location for each user.

Manage User Licenses Using Microsoft Entra PowerShell

Once these prerequisites are met, you can start managing user licenses with Entra PowerShell for the following tasks:

  1. Get a list of all Microsoft 365 licenses
  2. List all users assigned to a specific license
  3. Export users assigned to selected licenses using CSV
  4. View all Microsoft 365 licenses assigned to a user
  5. View all Microsoft 365 services assigned to a user
  6. Assign a specific Microsoft 365 license to a user
  7. Assign a specific Microsoft 365 license to multiple users
  8. Assign multiple licenses to a user
  9. Bulk assign licenses to multiple users
  10. Copy Microsoft 365 licenses from one user to another
  11. Identify licenses assigned to disabled users
  12. Remove all Microsoft 365 licenses from a user
  13. Bulk remove Microsoft 365 licenses from multiple users
  14. Remove specific licenses from a user account

1. Get a List of All Microsoft 365 Licenses

When organizations keep purchasing new Microsoft 365 licenses without reviewing existing allocations, unused licenses pile up and drive unnecessary costs. Regularly checking license status helps determine if additional licenses are actually required. Overall, this review helps optimize resource management.

To view all Microsoft 365 license plan details, use the Get-EntraSubscribedSku cmdlet as below:

list-of-all-available-entra-license-plans

This command retrieves details such as:

  • SkuId: Unique ID of the license plan.
  • SkuPartNumber: Identifier name of the license plan (for example, EMS for Enterprise Mobility + Security).
  • Enabled: Total number of licenses available for the purchased plan.
  • ConsumedUnits: Number of licenses currently assigned to users under the plan.
  • LockedOut, Suspended, Warning: Indicators that show the license health status.

2. List All Users Assigned to a Specific License

Now that you have details of available Microsoft 365 licenses, the next step is to identify which users are assigned to a specific license. This helps ensure that no user has unwanted or elevated licenses.

To view the users assigned to a particular license, you first need to find the SKU ID of that license plan. You can use the Get-EntraSubscribedId cmdlet to get the list of available license plans and their corresponding SKU IDs.

get-sku-id-for-all-license-plans

This cmdlet retrieves all available license plans along with their names and IDs. Once you have the required SKU IDs use the snippet below to list all Microsoft 365 users assigned to a specific license.

Replace <SkuId> with the SKU ID of the desired license plan to retrieve details such as display name, user principal name, ID, and account status. In the example below, the users assigned to the ‘CCIBOTS_PRIVPREV_VIRAL’ license plan are retrieved.

find-all-users-with-a-specific-license-plan

3. Export User Assigned to Selected Licenses Using CSV

Sometimes, you may need to review user assignments across multiple Microsoft 365 license plans to detect duplicate license assignments.

In such cases, you can use a CSV file containing the required SKU IDs as shown in the example below. Make sure that the same column name is used in both the CSV file and the script to avoid errors during execution.

sku-ids-csv-input

Once the file is ready, save it and run the following PowerShell snippet to export all users assigned to the selected license plans.

This retrieves all users assigned to the license plans listed in the CSV file. In the example below, users assigned to the FLOW_FREE, POWERAPPS_DEV, and POWER_BI_STANDARD licenses are displayed.

get-all-license-assignments-to-manage-user-licenses

4. View All Microsoft 365 Licenses Assigned to a User

Before assigning a license to a user, it’s important to check which licenses are already allocated to them. This prevents duplicate allocations from group-based license assignments and ensures that users don’t receive unnecessary or elevated privileges. To view the licenses assigned to a user, use the Get-EntraUserLicenseDetail cmdlet as below:

Replace <UserPrincipalName> with the UPN of the target user whose assigned licenses you want to check.

view-all-licenses-for-a-user

This command retrieves all the license plans currently assigned to the user, along with their SKU ID and SKU part number.

5. View All Microsoft 365 Services Assigned to a User

In addition to checking licenses, it’s also important to view all the service plans included within a user’s license. But before that, let’s understand what a service plan actually is. Think of license plan as a big package, for example, Microsoft 365 E5, Microsoft 365 E3, or Power BI Pro. Each of these packages includes several Microsoft 365 products, such as Exchange Online, SharePoint, Teams, and more. These individual components are called services, also known as service plans.

By checking all the service plans within a user’s license, you can ensure that each service is provisioned (enabled or disabled) correctly for the user.

To list all service plans available in a user’s assigned licenses, run the following cmdlet:

get-all-service-plans-in-license-plans

This command retrieves all the service plans included in the licenses assigned to the specified user, along with their provisioning status.

6. Assign a Specific Microsoft 365 License to a User

When onboarding a new employee, they’ll need access to Microsoft 365 apps like Outlook, Teams, and OneDrive. You can easily grant these by assigning the appropriate Microsoft 365 license to their account.

To assign a specific license to a user, use the Set-EntraUserLicense cmdlet as shown below:

Replace <UserPrincipalName> with the UPN of the target user and <SkuPartNumber> with the SKU name of the required license.

manage-user-licenses-assign-license-to-a-user

This snippet assigns the specified Microsoft 365 license to the user and verifies the assignment using the Get-EntraUserLicenseDetail cmdlet.

In this example, Sarah is assigned the Power Apps Developer (POWERAPPS_DEV) license plan. The final command verifies that the license was successfully applied to her account.

7. Assign a Specific Microsoft 365 License to Multiple Users

Assigning Microsoft 365 licenses manually can be time-consuming, especially when managing a large number of users. For example, if multiple users, such as contractors or external users are added to a new project, assigning licenses one by one becomes inefficient. To simplify this process, you can bulk assign Microsoft 365 licenses to multiple users at once using a CSV file as input.

To get started, create a CSV file containing the UserPrincipalName values of the users who need licenses as below:

bulk-assign-license-to-multiple-users-csv-input

Then, run the following PowerShell snippet, replacing <SkuPartNumber> with the required license plan.

8. Assign Multiple Licenses to a User

Suppose you need to assign more than one license to a user due to a role change that requires additional licenses. You can assign multiple licenses to the user in a single operation using the PowerShell snippet below:

Replace <SkuPartNumber1>, <SkuPartNumber1> with the appropriate SKU part names for the licenses and <UserPrincipalName> with the UPN of the target user.

9. Bulk Assign Licenses to Multiple Users

During a migration or license upgrade, you might need to replace existing plans with new ones for a large set of users. You can do this by importing a list of users from a CSV file and assigning the required licenses using PowerShell.

Create a CSV file containing the users’ principal names, as shown in the sample below:

bulk-assign-license-to-multiple-users-csv-input

Save the file and then run the snippet provided.

Replace <SkuPartNumber1>, <SkuPartNumber2>, and <FilePath> with your actual license SKU names and CSV file path. Once done, you can verify the assignment.

10. Copy Microsoft 365 Licenses from One User to Another (Template User Method)

Let’s say a new employee joins the HR department. If you already have an existing HR with all the necessary licenses assigned, you don’t need to manually assign licenses one by one to the new hire.
Instead, you can copy and apply the same licenses from the existing (template) user to the new (target) user.

To assign licenses to a new user based on a template user in Microsoft Entra ID, run the following PowerShell snippet:

Replace <TemplateUser> and <TargetUser> with the user principal names (UPNs) of your template and target users, respectively.

manage-user-licenses-assign-a-license-to-a-user-based-on-a-template-user

In this example, Sarah (template user) and Charlie (target user) end up with the same set of licenses after the script runs.

11. Identify Licenses Assigned to Disabled Users

In certain cases, user accounts may be disabled due to resignation, role changes, or security reasons. Such accounts may still hold assigned licenses, increasing costs and impacting overall license management. Therefore, it is essential to review disabled accounts regularly to ensure that no active licenses remain assigned to them.

To list all inactive users with active licenses, use the PowerShell snippet below:

get-disabled-users-with-active-licenses

This cmdlet retrieves all disabled users who still have active licenses and allows you to reassign them to required accounts as needed.

12. Remove All Microsoft 365 Licenses from a User

When a user is offboarded, it’s important to remove any licenses still assigned to them. You can use the following PowerShell snippet to remove all licenses from a single user.

Replace <UserPrincipalName> with the UPN of the user whose licenses you need to remove.

13. Bulk Remove Microsoft 365 Licenses for Multiple Users

When several employees leave your organization due to layoffs or contract completion, removing licenses one by one can be time-consuming. In such cases, you can use a CSV file to remove multiple users at once.

First, create a CSV file listing the users like the sample image given below:

manage-user-licenses-bulk-remove-license

Then, run the following PowerShell snippet to remove all licenses for the listed users.

Replace <FilePath> with the path to your CSV file. The licenses will be removed for all users listed in the file.

14. Remove Specific M365 Licenses from a User Account

When users no longer need certain services like Power BI or Visio, instead of removing all licenses, you can remove only the specific ones they no longer use. You can use the following PowerShell snippet to remove specific licenses from a user.

Replace <UserPrincipalName>, <SkuPartNumber1>, and <SkuPartNumber2> with the user’s UPN and the licenses you want to remove.

That’s a wrap! We hope this blog helped you manage M365 user licenses effectively using Entra PowerShell. With these easy-to-use scripts, you can streamline your license management and save both time and costs. Stay tuned for more practical guides, and don’t hesitate to share your questions or experiences in the comments below. We’d love to hear from you!

How to Manage User Licenses Using Microsoft Entra PowerShell

by Blesslin Rinu time to read: 11 min
0