How to Use Set-MsolUserLicense in Powershell

How to Use Set-MsolUserLicense in Powershell

Managing all the license options within an organization can turn into a daunting challenge if you don't know how to do it.

Fortunately for us, PowerShell has come to the rescue - the Set-MsolUserLicense cmdlet will help us assign, remove, and update user licenses within a few clicks.

Let's learn how to use Set-MsolUserLicense in PowerShell by following three easy steps.

What is the Set-MsolUserLicense Cmdlet?

Set-MsolUserLicense is a PowerShell cmdlet part of the Microsoft Online Services PowerShell module (MSOnline module), which allows administrators to manage user accounts and licenses in Microsoft 365 through PowerShell.

Specifically, Set-MsolUserLicense is used to assign or remove licenses for Microsoft 365 services to/from a user.

This cmdlet is helpful when you need to adjust the licensing configuration for individual users in your Microsoft 365 environment, and this is the syntax of Set-MsolUserLicense:

Set-MsolUserLicense

-ObjectId <Guid>

[-LicenseOptions <LicenseOption[]>]

[-AddLicenses <String[]>]

[-RemoveLicenses <String[]>]

[-TenantId <Guid>]

[<CommonParameters>]

Let's quickly explore the meaning of the parameters on the syntax:

  • ObjectId: Unique identifier for the user targeted for license modification.
  • LicenseOptions: Additional settings for license assignment (optional).
  • AddLicenses: Specifies the array of licenses to be added to the user.
  • RemoveLicenses Parameter: Licenses to be removed from the user.
  • TenantId: Identifier for the Microsoft 365 tenant (useful in multi-tenant environments).

What Can You Use Set-MsolUserLicense For?

By using Set-MsolUserLicense, organization administrators can perform active license management tasks such as the following:

  • Onboarding a New Employee: When a new employee joins the company, use Set-MsolUserLicense to grant them access to Microsoft 365 services by assigning a specific license, such as one that includes email, collaboration tools, and other applications.
  • Offboarding a Departing Employee: When an employee leaves the organization, use the cmdlet to remove their Microsoft 365 license, ensuring that they no longer have access to company resources and services.
  • Adjusting License Plans for Role Changes: If an employee's role changes within the organization, use Set-MsolUserLicense to modify their license plan. For example, upgrade a user to a plan that offers more advanced features or downgrade to a plan with fewer features based on their new responsibilities.

How to Use Set-MsolUserLicense in PowerShell

To use Set-MsolUserLicense, we'll follow three quick steps.

Step 1: Connect to Office 365

First, we need to connect to Exchange Online PowerShell by using the following command:

Connect-ExchangeOnline -UserPrincipalName [email protected]

Then, we'll use this command to access the Microsoft Office 365 module:

Connect-MsolService

Remember to log in using your own Microsoft credentials (email address and password) with enough admin permissions to proceed.

Step 2: Run Set-MsolUserLicense

Once you have connected to the desired environment, it's time to run the Set-MsolUserLicense command. Take a look at the following example:

Set-MsolUserLicense -UserPrincipalName "[email protected]" -AddLicenses "MeetingRoom365:ENTERPRISEPACK"

In this case, the command adds the Office 365 for Enterprises license to the user [email protected].

If, instead of adding licenses to the current user, you wish to remove them, then the command would look like this:

Set-MsolUserLicense -UserPrincipalName "[email protected]" -RemoveLicenses "MeetingRoom365:ENTERPRISEPACK"

This cmdlet removes the Office 365 for Enterprises license from the user [email protected].

Step 3: Verify the Changes Using the Get-MsolUser Cmdlet

After running the Set-MsolUserLicense command, it's time to verify the new licensed users (or unlicensed users) to see if the changes have been correctly applied.

To do this, run the following command:

Get-MsolUser -UserPrincipalName [email protected]

This command retrieves and displays information about the specified user, including their assigned licenses. This way, you can check that all the changes were correctly applied as expected.

Wrapping Up: Using the Set-MsolUserLicense Command

Using the Set-MsolUserLicense command provides us with more control over the different licenses that users in an organization can have.

Either way, keep in mind that due to the recent changes in the Azure Active Directory module, Microsoft is planning to deprecate certain PowerShell commands in March, 2024.

In that case, it's important to learn how to license users with other commands, such as the Set-MgUserLicense cmdlet.