How to manage Microsoft 365 user licenses using Set-MgUserLicense

Managing Microsoft 365 user licenses

Assigning or removing Microsoft 365 licenses is a common task for IT admins, but doing it with PowerShell isn't always straightforward. It requires fetching the correct SKU ID (the unique identifier for each license), handling precise syntax with hash tables, and ensuring the user has the required attributes like UsageLocation set. On the other hand, ADManager Plus, a Microsoft 365 management and reporting tool, eliminates this complexity. With a few clicks, you can assign or remove licenses for multiple users, filter by group, and skip the scripting altogether.

  • ADManager Plus
  • PowerShell
 

Assign or remove Microsoft 365 user licenses using ADManager Plus

  1. Log in to ADManager Plus and navigate to the Microsoft 365 tab.
  2. Under the Management section, click on License Management → Assign/Remove Licenses.
  3. Select the appropriate Microsoft 365 tenant account.
  4. Choose the users to whom you want to assign or remove licenses. ADManager Plus supports bulk license assignments and lets you assign licenses by group.
Assigning Microsoft 365 user licenses using ADManager Plus

Manage Microsoft 365 user licenses using Microsoft Graph PowerShell

Prerequisites

Before using the Set-MgUserLicense cmdlet, make sure the following requirements are met:

  • Install the Microsoft Graph PowerShell module.
    Install-Module Microsoft.Graph -Scope CurrentUser
  • Connect to Microsoft Graph PowerShell with the required scopes.
    Connect-MgGraph -Scopes "User.ReadWrite.All", "Directory.ReadWrite.All"
  • Ensure the user has UsageLocation set.

Using the Set-MgUserLicense command to manage Microsoft 365 user licenses

The Set-MgUserLicense cmdlet can be used in Microsoft Graph PowerShell to manage Microsoft 365 user licenses.

Here's the syntax:

Set-MgUserLicense
-UserId <String>
[-AddLicenses <IMicrosoftGraphAssignedLicense[]>]
[-RemoveLicenses <String[]>]
[-AdditionalProperties <Hashtable>]
[-ResponseHeadersVariable <String>]
[-Headers <IDictionary>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]

Supported parameters:

The following table contains some parameters that can be used along with the Set-MgUserLicense command to manage Microsoft 365 user licenses efficiently.

Parameter Description
-UserId Specifies the user (by UPN or object ID) whose license is being modified.
-AddLicenses An array of license objects to assign. At a minimum, each object must include a SKU ID.
-RemoveLicenses An array of license SKU IDs to remove from the user.
-AdditionalProperties Passes any extra parameters supported by the API request body.
-ResponseHeadersVariable Stores response headers in a variable.
-Headers Custom request headers.
-WhatIf Shows what would happen if the cmdlet runs.
-Confirm Prompts for confirmation before execution.

Limitations of using Graph PowerShell scripts to manage Microsoft 365 user licenses

  • IT admins need to be comfortable writing and debugging PowerShell when dealing with hash tables and GUIDs for license assignments.
  • Managing licenses for large groups of users requires loops, filters, and error handling, which slows down execution.
  • Errors like invalid SKU IDs or missing attributes can take time to identify and resolve without proper logging in place.
  • There"s no built-in UI to track who has what license, making audits and license optimization harder.

Highlights of using ADManager Plus to manage Microsoft 365 user licenses

  • Provides an intuitive interface, eliminating the need for PowerShell scripting.
  • Enables easy assignment, removal, modification, and replacement of Microsoft 365 licenses without dealing with complex commands.
  • Supports bulk license management across users and groups, saving time and effort.
  • Offers built-in automation to handle recurring license tasks without manual input.
  • Allows delegation of specific license management tasks to help desk technicians without giving full admin access.

Assign Microsoft 365 license to users using ADManager Plus

 
  • Managing Microsoft 365 user licenses
  • Assign or remove Microsoft 365 user licenses using ADManager Plus
  • Manage Microsoft 365 user licenses using Microsoft Graph PowerShell
  • Limitations of using Graph PowerShell scripts to manage Microsoft 365 user licenses
  • Highlights of using ADManager Plus to manage Microsoft 365 user licenses
The one-stop solution to Active Directory Management and Reporting
Email Download Link Email the ADManager Plus download link