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
- Microsoft Graph installed and configured. If you don’t know how to do that. Here’s my blog post about the Microsoft 365 Setup for Microsoft Graph PowerShell SDK
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.