Forum Discussion

Citizen8675309's avatar
Citizen8675309
Copper Contributor
Dec 04, 2023

Bug or Error with documentation Set-MgUserLicense

When I attempt to run the PowerShell command as https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.users.actions/set-mguserlicense?view=graph-powershell-1.0#example-2-assign-more-than-one-licenses-to-a-user it's not working as expected. 

Here is my example (please note for the purposes of this discussion I've changed the last two characters of the User Id.) 

Neither a single line of code or the foreach loop is working.

 

foreach ($User in $DataFile){
Update-MgUser -UserId "$username@$UPN" -UsageLocation US

$1 = Get-MgSubscribedSku -All | Where SkuPartNumber -EQ 'blah'
$2 = Get-MgSubscribedSku -All | Where SkuPartNumber -EQ 'blah'
$3 = Get-MgSubscribedSku -All | Where SkuPartNumber -EQ 'blah'
$AddLicenses = @(
@{SkuId = $1.SkuId},
@{SkuId = $2.SkuId},
@{SkuId = $3.SkuId},
)
$ID = Get-MgUser -UserId $user.UPN | select ID
Set-MgUserLicense -UserId $ID.Id -AddLicenses $AddLicenses -RemoveLicenses @()
}

 

Set-MgUserLicense : Cannot convert the literal '' to the expected type 'Edm.Guid'.
Status: 400 (BadRequest)
ErrorCode: Request_BadRequest
Date: 2023-12-04T18:45:05
Headers:
Transfer-Encoding : chunked
Vary : Accept-Encoding
Strict-Transport-Security : max-age=31536000
request-id : 600fc507-5367-4099-bf96-a61e7d616c0a
client-request-id : 46b15524-e5c6-44bc-8fb9-fd574f443544
x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"Canada East","Slice":"E","Ring":"2","ScaleUnit":"001","RoleInstance":"QB1PEPF000049EE"}}
x-ms-resource-unit : 1
Cache-Control : no-cache
Date : Mon, 04 Dec 2023 18:45:05 GMT
At line:15 char:1
+ Set-MgUserLicense -UserId $ID.Id -AddLicenses $AddLicenses -RemoveLic ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: ({ UserId = 3800...ionJsonSchema }:<>f__AnonymousType8`2) [Set-MgUserLicense_AssignExpanded], Exception
+ FullyQualifiedErrorId : Request_BadRequest,Microsoft.Graph.PowerShell.Cmdlets.SetMgUserLicense_AssignExpanded

 

PS C:\WINDOWS\system32> Set-MgUserLicense -UserId '3800cc3a-b26c-46cf-8ccb-a7bcae482axx' -AddLicenses $AddLicenses -RemoveLicenses @()
Set-MgUserLicense : Cannot convert the literal '' to the expected type 'Edm.Guid'.
Status: 400 (BadRequest)
ErrorCode: Request_BadRequest
Date: 2023-12-04T18:27:41
Headers:
Transfer-Encoding : chunked
Vary : Accept-Encoding
Strict-Transport-Security : max-age=31536000
request-id : fddee7ec-01f1-4266-ba62-cb3808336b27
client-request-id : e0fe4ebe-5e4a-42f2-b980-b2b6c15f0d8c
x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"East US","Slice":"E","Ring":"5","ScaleUnit":"001","RoleInstance":"MN1PEPF00010627"}}
x-ms-resource-unit : 1
Cache-Control : no-cache
Date : Mon, 04 Dec 2023 18:27:41 GMT
At line:1 char:1
+ Set-MgUserLicense -UserId '3800cc3a-b26c-46cf-8ccb-a7bcae482a06' -Add ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: ({ UserId = 3800...ionJsonSchema }:<>f__AnonymousType8`2) [Set-MgUserLicense_AssignExpanded], Exception
+ FullyQualifiedErrorId : Request_BadRequest,Microsoft.Graph.PowerShell.Cmdlets.SetMgUserLicense_AssignExpanded

No RepliesBe the first to reply