azure - Problem assigning license to an Office 365 user with PowerShell - Stack Overflow

This command fails. What am I doing wrong?LicenceUser = Set-MgUserLicense -UserId $userid -Addlicenses

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.

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.

Share Improve this question edited Apr 17 at 1:04 user4157124 2,99614 gold badges31 silver badges46 bronze badges asked Feb 27 at 8:43 Nick_KNick_K 6338 silver badges23 bronze badges 13
  • Try $LicenceUser = Set-MgUserLicense -UserId $userid -AddLicenses @{SkuId = ($license.SkuId)} -RemoveLicenses $null -ErrorAction Stop – Rukmini Commented Feb 27 at 8:51
  • Thank you. Same message. It is so strange! – Nick_K Commented Feb 27 at 9:01
  • Which version are you using? – Rukmini Commented Feb 27 at 9:21
  • 1 It worked for me in Microsoft Graph Explorer like this – Rukmini Commented Feb 27 at 9:53
  • 1 Yes many commands are not working:) – Rukmini Commented Mar 4 at 7:59
 |  Show 8 more comments

1 Answer 1

Reset to default 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/microsoftgraph/msgraph-sdk-powershell/issues/3201. For now I'd recommend doing a direct API call which should work consistently.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745140056a4613387.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信