Using Microsoft Graph PowerShell to assign Microsoft 365 licenses

Those who have been working with Microsoft 365 SaaS products will be familiar with the MSOnline PowerShell modules that were deprecated as of March 30, 2024. One of the cmdlets I frequently used were the Get-MsolUser and Set-MsolUserLicense for assigning Microsoft 365 licenses when working with an organization with a large amount of users. With the retirement of the legacy cmdlet, I wanted to share a script I had created a while back that demonstrates how we can use Microsoft Graph’s Get-MgUser (https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.users/get-mguser?view=graph-powershell-1.0) and Set-MgUserLicense (https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.users.actions/set-mguserlicense?view=graph-powershell-1.0) PowerShell cmdlets to generate reports of licenses and assign licenses.

The following GitHub repo PowerShell script provides the samples listed below: https://github.com/terenceluk/Microsoft-365/blob/main/Administration/Assign-M365-Licenses.ps1

  1. Generate a Microsoft 365 license report with GUI and console text. Use this to retrieve the skuID required for assigning licenses
  2. Get all users with a assigned E5 license SKU
  3. Swap out users assigned with an expired Microsoft 365 E5 with a valid E5
  4. Retrieve all the users who have a Microsoft 365 E5 license assigned and assign them with a Copilot license