2

This command fails. What am I doing wrong?

LicenceUser = Set-MgUserLicense -UserId $userid -Addlicenses @{SkuId = ($license.SkuId)} -RemoveLicenses @() -ErrorAction:Stop;

This part is fine:

-Addlicenses @{SkuId = ($license.SkuId)}

So is this:

-RemoveLicenses @()

This is the error message:

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

0

1 Answer 1

3

According to the documentation the call you're making looks correct, however these documentations for Graph Module are usually wrong, a correct API call to assignLicense would be:

# Requires Scopes, one of:
#    LicenseAssignment.ReadWrite.All
#    Directory.ReadWrite.All
#    User.ReadWrite.All

$userId = 'xxxxx-xxxx-xxxx-....'

Invoke-MgGraphRequest POST "v1.0/users/$userId/assignLicense" -Body @{
    removeLicenses = @()
    addLicenses    = @(
        @{
            skuId         = $license.SkuId
            disabledPlans = @()
        }
    )
}

Which, makes me think -AddLicenses should be passed as an array:

Set-MgUserLicense -UserId $userid -AddLicenses @(@{ SkuId = $license.SkuId }) -RemoveLicenses @()

EDIT

Unfortunately there seems to be a bug with the cmdlets as OP has found out, see https://github.com/microsoftgraph/msgraph-sdk-powershell/issues/3201. For now I'd recommend doing a direct API call which should work consistently.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. It does not work. It fails displaying the same message. But I just found this: github.com/microsoftgraph/msgraph-sdk-powershell/issues/3201

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.