Skip to content

Set-MgUserLicense optimizes out necessary empty parameters #3273

@dt-flo

Description

@dt-flo

Describe the bug

I hope the titel is alright, please tell me if I should change it if it is unclear.
When running the command Set-MgUserLicense -UserId "[email protected]" -RemoveLicenses @("b70a4eeb-32f6-4c99-af47-3c822a4bbc59") -AddLicenses @() as described for example in Example 6 in the MS docs, the Graph SDK detects that -AddLicenses @() is essentially empty and omits it from the HTTP request. However, the Microsoft Graph API requires that AddLicenses is present even though it is empty. The same behavior can be reproduced with RemoveLicenses

Example:
Set-MgUserLicense -UserId "[email protected]" -RemoveLicenses @() -AddLicenses @() -Debug results in

DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
POST

Absolute Uri:
https://graph.microsoft.com/v1.0/users/REDACTED/microsoft.graph.assignLicense

Headers:
FeatureFlag                   : 00000003
Cache-Control                 : no-store, no-cache
User-Agent                    : Mozilla/5.0,(Windows NT 10.0; Microsoft Windows 10.0.26100; de-DE),PowerShell/7.5.0
SdkVersion                    : graph-powershell/2.26.1
client-request-id             : REDACTED
Accept-Encoding               : gzip,deflate,br

Body:
{}

an empty body and therefor in the error

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

Status: 400 (BadRequest)
ErrorCode: Request_BadRequest
Date: 2025-04-15T10:59:24

. The command Set-MgGroupLicense has the exact same issue. I am using Graph SDK 2.26.1.

Expected behavior

The SDK should neither omit AddLicenses, nor RemoveLicenses

How to reproduce

See section "Describe the bug"

SDK Version

2.26.1

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions