Skip to content

Set-MgUserLicense mandates addLicenses parameter #3245

@dwarfered

Description

@dwarfered

Describe the bug

Removing a license using Set-MgUserLicense throws an error in ModuleVersion="2.26.1

Set-MgUserLicense -UserId $account.Id -AddLicenses @() -RemoveLicenses @($skuId)
Set-MgUserLicense -UserId $account.Id -RemoveLicenses @($skuId)

"One or more parameters of the operation 'assignLicense' are missing from the request payload. The missing parameters are: addLicenses"

Expected behavior

Set-MgUserLicense -UserId $account.Id -AddLicenses @() -RemoveLicenses @($skuId)

How to reproduce

Passing empty array of AddLicenses or not passing the parameter at all

Set-MgUserLicense -UserId $account.Id -AddLicenses @() -RemoveLicenses @($skuId)
Set-MgUserLicense -UserId $account.Id -RemoveLicenses @($skuId)

SDK Version

2.26.1

Latest version known to work for scenario above?

2.25.0

Known Workarounds

        $body = @{
            addLicenses    = @()
            removeLicenses = @(
                "$skuId"
            )
        } | ConvertTo-Json
        
        $params = @{
            Method      = 'POST'
            Uri         = "https://graph.microsoft.com/v1.0/users/$($account.Id)/assignLicense"
            Body        = $body
            ContentType = "application/json"
        }

        Invoke-MgGraphRequest @params

Debug output

Click to expand log ```
</details>


### 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