Set-MgUserLicense Error message

Kathryn Anderson 40 Reputation points
2025-03-07T15:45:18.94+00:00

I have been trying to get Set-MgUserLicense to work for days now but every time I run this script I get this error message.

Set-MgUserLicense : One or more parameters of the operation 'assignLicense' are missing from the request payload. The missing parameters are: removeLicenses

I have not changed anything with my script, it just stopped working. Is there an issue with Set-MgUserLicense? I really need to get this working again as it is vital to how we work and assign new users licenses.

Thanks

Microsoft Security Microsoft Graph
{count} votes

5 answers

Sort by: Most helpful
  1. Quaine Day 55 Reputation points
    2025-03-28T20:13:38.6733333+00:00

    Solution for Set-MgUserLicense Bug in Microsoft Graph PowerShell SDK 2.26.1

    After seeing continued issues with this problem and testing extensively myself, I've confirmed this is indeed a bug in Microsoft Graph PowerShell SDK version 2.26.1. Even when following the documented syntax with -RemoveLicenses @(), the command fails with the error:

    Set-MgUserLicense : One or more parameters of the operation 'assignLicense' are missing from the request payload. The missing parameters are: removeLicenses.
    

    Workaround Solution

    Rather than downgrading to version 2.25.0 (which works but isn't always feasible), I've developed a complete solution that bypasses the broken cmdlet entirely by using direct Graph API calls through Invoke-MgGraphRequest.

    I've published a fully-functional interactive script that:

    • Shows all licenses assigned to a user in a menu
    • Allows selecting specific licenses to remove or all licenses at once
    • Confirms changes before executing
    • Verifies the remaining licenses after removal

    You can find the complete script in my GitHub repository:
    MgGraph-PowerShell-Tools

    The Key Code That Fixes the Issue

    The critical part that works around the bug is:

    # Create JSON payload for license removal
    $jsonBody = @{
        addLicenses    = @()  # Must be explicitly empty
        removeLicenses = $LicensesToRemove
    } | ConvertTo-Json -Depth 10
    # Send Graph API request to remove the licenses
    Invoke-MgGraphRequest -Method POST -Uri "https://graph.microsoft.com/v1.0/users/$($UserId)/assignLicense" -Body $jsonBody -ContentType "application/json"
    

    This approach completely bypasses the problematic cmdlet and interacts directly with the Graph API endpoint, ensuring the correct payload format.

    Why This Works

    The bug appears to be in how the cmdlet constructs the request payload, not in the Graph API itself. By constructing the JSON payload manually and using Invoke-MgGraphRequest, we ensure that:

    1. Both required parameters (addLicenses and removeLicenses) are explicitly included in the request
    2. The proper format is maintained for the Graph API endpoint
    3. We avoid whatever internal issue is causing the cmdlet to fail

    Using the Solution

    You can use my script directly from the repository, or integrate the key code part into your existing solutions. The script works with Microsoft.Graph 2.26.1 and should continue to work even after Microsoft fixes this bug.

    I've tested this solution with multiple user accounts and license types, and it reliably removes licenses where the standard cmdlet fails.

    8 people found this answer helpful.

  2. Rajat Vashistha-MSFT 1,690 Reputation points Microsoft External Staff
    2025-03-07T17:19:12.42+00:00

    Hi Kathryn Anderson,

    Thanks for reaching out to Microsoft!

    The error message you’re encountering with Set-MgUserLicense indicates that the removeLicenses parameter is missing from the request payload. When using this cmdlet, both -AddLicenses and -RemoveLicenses parameters need to be explicitly provided, even if one of them is empty.

    If you don’t have any licenses to remove, please try including the -RemoveLicenses @() parameter in your command and check if it resolves the issue.

    You can refer to the relevant documentation for more details: Set-MgUserLicense

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote. If you have any further questions about this answer, please click Comment.


  3. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  4. Jim Cox 0 Reputation points
    2025-03-27T17:41:07.1733333+00:00

    As a side note. The command does work with a GUID passed in for -RemoveLicenses but will not work with and empty array @().

    So basically you have to remove a license to assign a license.....Hmmm.


  5. Yamada Yuki 0 Reputation points
    2025-03-28T02:53:40.17+00:00

    Graphモジュールのバージョンを2.23.0にすると事象が解消されるようです。

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.