Set-MgGroupLicense - error assignLicense are missing parameters addLicenses
Published on 18 Mar 2025The Set-MgGroupLicense command can cause issues when attempting to remove a license from a group by passing an empty list for AddLicenses, even though this follows the official documentation.
Clap
Problème assignLicense are missing parameters addLicenses
The Set-MgGroupLicense
command can cause issues when attempting to remove a license from a group by passing an empty list for AddLicenses
, even though this is in accordance with the official documentation.
Set-MgGroupLicense_Assign: One or more parameters of the operation 'assignLicense' are missing from the request payload. The missing parameters are: addLicenses.
This error occurs with module 2.26.1 (other versions have not been tested).
For reference, below are the non-working codes:
# Test 1 KO
$groupID = 'xxx
$group = Get-MgGroup -GroupId $groupId -Property AssignedLicenses
$licensesToRemove = $group.AssignedLicenses.SkuId
$params = @{
addLicenses = @() # Empty array for addLicenses
removeLicenses = $licensesToRemove
}
Set-MgGroupLicense -GroupId $groupId -BodyParameter $params
# Test 2 KO
Set-MgGroupLicense -GroupId xxx -AddLicenses @() -RemoveLicenses @('xxx')
# Test 3 KO
Set-MgGroupLicense -GroupId xxx -AddLicenses @{} -RemoveLicenses @('xxx')
Alternative Solution with Invoke-MgGraphRequest
To work around this issue, I used Invoke-MgGraphRequest
, which allows direct calls to the Graph API with a properly formatted request body.
Here is a functional PowerShell script:
$groupId = 'xxx'
# Retrieve the group's current licenses
$group = Get-MgGroup -GroupId $groupId -Property AssignedLicenses
$licensesToRemove = $group.AssignedLicenses.SkuId
# Prepare the request body to remove all licenses
$body = @{
addLicenses = @()
removeLicenses = $licensesToRemove
}
# Call the Graph API to remove licenses
Invoke-MgGraphRequest -Method POST -Uri "https://graph.microsoft.com/v1.0/groups/$groupId/assignLicense" -Body ($body | ConvertTo-Json)
This approach avoids the errors encountered with Set-MgGroupLicense
and ensures proper functionality.
Hopefully, a future update to the Microsoft.Graph modules will resolve this issue.
Clap
Comments