Swap Microsoft 365 Licenses with Microsoft Graph

Swap Microsoft 365 Licenses with Microsoft Graph
Swap Microsoft 365 Licenses with Microsoft Graph

A few years ago I wrote a post about how to Swap Office 365 Licenses. Microsoft has deprecated the cmdlets that were used in that post specifically Set-MsolUserLicense and has replaced them with Microsoft Graph cmdlets specifically Set-MgUserLicense.

In this post, I will show step-by-step how to swap Microsoft 365 licenses using Microsoft Graph and PowerShell.

Prerequisites

The Process

We need a few more permissions than the default permissions for Microsoft Graph.

  • Run the following command to connect Microsoft Graph to your Microsoft 365 tenant with the necessary permissions Connect-MgGraph -Scopes User.ReadWrite.All, Organization.Read.All

Now let’s find out what SKUs we have to work with.

  • Run the following command to get the list of SKUs in your Microsoft 365 tenant Get-MgSubscribedSku -All | select SkuPartNumber

If you aren’t sure what product the SKU correlates to Microsoft has made a decoder ring, you can find that here.

Now for the license swap part, I’ve created a PowerShell script to do it.

You can find the Script on my GitHub https://github.com/thedxt/Microsoft-365/tree/main#lic-swap-ms-graphps1

Change the variables for remove_LIC and add_LIC to match your needs.

The script will find all the users that have the SKU for the license you want to remove.

From the results, it will run a for-each loop that removes the license and outputs details on the removed license along with the UPN (User Principal Name) of the user it was removed from.

The script will then move on to adding the license and will output details on the added license and the UPN of the user it was added to.

The magic that makes the script work is the command Set-MgUserLicense.

That’s all it takes to switch Microsoft 365 licenses using Microsoft Graph.

If you want to read more about the Set-MgUserLicense cmdlet you can do so by reading the Microsoft documentation here.

2 responses to “Swap Microsoft 365 Licenses with Microsoft Graph

Jerry

Life saver!

Daniel Keer

Glad it helped.

Leave a comment

Your email address will not be published. Required fields are marked *