I need to assign license using MsGraph-if you are here, you know it will be obsolete by the end of March.
So far, I found this.
$AddLicense = @(
@{SkuID = $license DisabledPlans = $DisabledPlans})
Set-MgUserLicense -UserID $upn -AddLicenses $AddLicense -RemoveLicenses @()
Where:
$license is only the AccountSkuId, cuz you don’t need the domain anymore
$DisabledPlans is in this case MFA_PREMIUM (This is tested for EMSPREMIUM license)
The error I get:
Set-MgUserLicense : Cannot convert the literal ‘EMSPREMIUM’ to the expected type ‘Edm.Guid’.
At line:5 char:15
- … Set-MgUserLicense -UserID $upn -AddLicenses $AddLicense – …
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : InvalidOperation: ({ UserId = jneb…ionJsonSchema }:<>f__AnonymousType8
2) [Set-MgUserLicense_AssignExpanded1], RestException
1 - FullyQualifiedErrorId : Request_BadRequest,Microsoft.Graph.PowerShell.Cmdlets.SetMgUserLicense_AssignExpanded1
I think the problem is teh $license variable.
- CategoryInfo : InvalidOperation: ({ UserId = jneb…ionJsonSchema }:<>f__AnonymousType8
Thank you in advance for your help!
2
Answers
I tried to reproduce the same in my environment and below is the result
Thanks to @jdweng for suggesting same point.
SkuPartNumber = "EMSPREMIUM"
I have used below PowerShell code to assign the EMS E5 license to user.
Output:
When I check the same in portal, license got assigned to user successfully.
Refer: Assigning licenses to user accounts for details about license assignment using Msgraph PowerShell.
Hello if you need to use rest api requests instead of the cmdlets, below is how i would assign a single user office365 license.