How to Assign Licenses to User Accounts with Microsoft 365 PowerShell

Assigning Microsoft 365 licenses to user accounts can be streamlined with PowerShell. This guide shows IT admins how to install the module, connect to the tenant, get available licenses, assign licenses, and verify assignments – a scalable approach.

How to Assign Licenses to User Accounts with Microsoft 365 PowerShell

If you're an IT administrator managing a Microsoft 365 environment, you know how crucial it is to ensure that your users have the right licenses assigned to their accounts. While you can perform this task through the Microsoft 365 admin center, using PowerShell can be a more efficient and scalable approach, especially when dealing with a large number of users or automating the process.

In this blog post, we'll walk you through the steps to assign licenses to user accounts with Microsoft 365 PowerShell.

Step 1: Install the Microsoft 365 PowerShell Module Before you can start assigning licenses, you'll need to install the Microsoft 365 PowerShell module. Open an elevated PowerShell window and run the following command:

Install-Module -Name Microsoft.PowerApps.Administration.PowerShell

Step 2: Connect to Microsoft 365 Once the module is installed, you'll need to connect to your Microsoft 365 tenant. Run the following command and enter your admin credentials when prompted:

Connect-MsolService

Step 3: Get a List of Available Licenses To see the licenses available in your tenant, run the following command:

Get-MsolAccountSku

This will display a list of license plans and their respective account SKU IDs.

Step 4: Assign Licenses to User Accounts To assign a license to a user account, you'll need the user's principal name (UPN) and the account SKU ID of the license you want to assign. Run the following command, replacing <UPN> with the user's UPN and <AccountSkuId> with the desired license's account SKU ID:

Set-MsolUserLicense -UserPrincipalName <UPN> -AddLicenses <AccountSkuId>

For example, to assign the Microsoft 365 E3 license to the user john@dynamicendpoints.com, you would run:

Set-MsolUserLicense -UserPrincipalName john@dynamicendpoints.com -AddLicenses contoso:ENTERPRISEPACK

Step 5: Verify the Assigned Licenses To verify that the license has been assigned correctly, run the following command, replacing <UPN> with the user's UPN:

Get-MsolUser -UserPrincipalName <UPN> | Select DisplayName,Licenses

This will display the user's display name and the licenses assigned to their account.

By following these steps, you can efficiently assign licenses to user accounts in your Microsoft 365 environment using PowerShell. This approach can save you time and effort, especially when managing a large number of users or automating the process.

For more detailed information and additional examples, refer to the official Microsoft documentation: Assign licenses to user accounts with Microsoft 365 PowerShell