Assign M365 Licences with Graph API PowerShell

This article will show how to assign Microsoft 365 licenses to users using the Graph API PowerShell module.

Licensing Microsoft 365 users using automation can save time and effort in streamlining operations and free up time for more project work.

Graph API PowerShell allows us to manage almost every Microsoft 365 setting and configuration programmatically.

To get started with Graph API, visit our Graph API page and configure App Registration authentication using a certificate. The required App Registration permissions are Directory.ReadWrite.All


The following code will assign a Microsoft 365 E3 license to a user. To find out the license SKU, license a user first using the portal and run the following cmdlet Get-MgUserLicenseDetail -UserId | fl

Import-Module Microsoft.Graph.Users.Actions
$params = @{
	addLicenses = @(
			skuId = "6fd2c87f-b296-42f0-b197-1e91e994b900"
	removeLicenses = @(



Update-MgUser -UserId $userId  -usageLocation "AU"
Set-MgUserLicense -UserId $userId -BodyParameter $params

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.