Published: 30.Jun 2021

How to remove license from a group via MS Graph API and PowerShell

First step is to connect to MS Graph API, which is described here.

Then we need two attributes:

  • Group ID (object ID)
  • License ID (sku ID)

To find out GroupID, we can use Get-MsolGroup cmdlet, or check group properties via GUI or we can use MS Graph API as shown below:

$apiUrl = ''
$Data = Invoke-RestMethod -Headers @{Authorization = "Bearer $($token)"} -Uri $apiUrl -Method Get
$Groups = ($Data | select-object Value).Value | Select-Object id,displayName

# Show the groups

Then we need License skuId/GUID (Please check MS website for Product names and service plan identifiers for licensing or amazing blog of one of my colleague Philipp Foeckeler)

$apiUrl = '<GUID>?$select=assignedLicenses'
$Data = Invoke-RestMethod -Headers @{Authorization = "Bearer $($token)"} -Uri $apiUrl -Method Get
$GroupData = $Data | select-object -ExpandProperty assignedLicenses

$GroupData | fl

Output of the code:

Next, as we have all the information we need, we can proceed with license removal.
Update variables $LicenseToRemove and $groupID with your IDs.

$LicenceToRemove    = "c42b9cae-ea4f-4ab7-9717-81576235ccac"
$groupID            = "GROUP OBJECT ID"

$apiUrl             = "$groupID/assignLicense"


# REMOVE License Body for RestAPI
$body = @{
    addLicenses = @()
    removeLicenses= @($LicenceToRemove)

# Convert it to JSON
$jsonBody = $body | ConvertTo-Json

$removeLicense = Invoke-RestMethod -Method Post -Headers @{
    Authorization = "Bearer $($token)"
    'Content-Type'  = "application/json"
} -Body $jsonBody -Uri $apiUrl



5 3 votes
Article Rating
Notify of
1 Comment
Newest Most Voted
Inline Feedbacks
View all comments
23 days ago

FWIW, this is the c# code I created based on this article. Using the Rest.Sharp nuget library.

        addLicenses = new string[] { },
        removeLicenses = new[] { guid }

Last edited 23 days ago by feelie75 - Lubomir Goban  ---  Find me on - 
Would love your thoughts, please comment.x