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 2 votes
Article Rating
Notify of
Inline Feedbacks
View all comments - Lubomir Goban  ---  Find me on - 
Would love your thoughts, please comment.x