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:
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 | Show 8 more commentsSet-MgUserLicense : One or more parameters of the operation 'assignLicense' are missing from the request payload. The missing parameters are: removeLicenses.
1 Answer
Reset to default 3According 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
$LicenceUser = Set-MgUserLicense -UserId $userid -AddLicenses @{SkuId = ($license.SkuId)} -RemoveLicenses $null -ErrorAction Stop
– Rukmini Commented Feb 27 at 8:51