Set-MgUserLicense
Add or remove licenses for the user to enable or disable their use of Microsoft cloud offerings that the company has licenses to. For example, an organization can have a Microsoft 365 Enterprise E3 subscription with 100 licenses, and this request assigns one of those licenses to a specific user. You can also enable and disable specific plans associated with a subscription. Direct user licensing method is an alternative to group-based licensing.
Note
To view the beta release of this cmdlet, view Set-MgBetaUserLicense
Syntax
AssignExpanded (Default)
Set-MgUserLicense
-UserId <string>
[-ResponseHeadersVariable <string>]
[-AddLicenses <IMicrosoftGraphAssignedLicense[]>]
[-AdditionalProperties <hashtable>]
[-RemoveLicenses <string[]>]
[-Break]
[-Headers <IDictionary>]
[-HttpPipelineAppend <SendAsyncStep[]>]
[-HttpPipelinePrepend <SendAsyncStep[]>]
[-Proxy <uri>]
[-ProxyCredential <pscredential>]
[-ProxyUseDefaultCredentials]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Assign
Set-MgUserLicense
-UserId <string>
-BodyParameter <IComponents103UmuuRequestbodiesAssignlicenserequestbodyContentApplicationJsonSchema>
[-ResponseHeadersVariable <string>]
[-Break]
[-Headers <IDictionary>]
[-HttpPipelineAppend <SendAsyncStep[]>]
[-HttpPipelinePrepend <SendAsyncStep[]>]
[-Proxy <uri>]
[-ProxyCredential <pscredential>]
[-ProxyUseDefaultCredentials]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
AssignViaIdentityExpanded
Set-MgUserLicense
-InputObject <IUsersActionsIdentity>
[-ResponseHeadersVariable <string>]
[-AddLicenses <IMicrosoftGraphAssignedLicense[]>]
[-AdditionalProperties <hashtable>]
[-RemoveLicenses <string[]>]
[-Break]
[-Headers <IDictionary>]
[-HttpPipelineAppend <SendAsyncStep[]>]
[-HttpPipelinePrepend <SendAsyncStep[]>]
[-Proxy <uri>]
[-ProxyCredential <pscredential>]
[-ProxyUseDefaultCredentials]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
AssignViaIdentity
Set-MgUserLicense
-InputObject <IUsersActionsIdentity>
-BodyParameter <IComponents103UmuuRequestbodiesAssignlicenserequestbodyContentApplicationJsonSchema>
[-ResponseHeadersVariable <string>]
[-Break]
[-Headers <IDictionary>]
[-HttpPipelineAppend <SendAsyncStep[]>]
[-HttpPipelinePrepend <SendAsyncStep[]>]
[-Proxy <uri>]
[-ProxyCredential <pscredential>]
[-ProxyUseDefaultCredentials]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Description
Add or remove licenses for the user to enable or disable their use of Microsoft cloud offerings that the company has licenses to. For example, an organization can have a Microsoft 365 Enterprise E3 subscription with 100 licenses, and this request assigns one of those licenses to a specific user. You can also enable and disable specific plans associated with a subscription. Direct user licensing method is an alternative to group-based licensing.
Permissions
Permission type | Permissions (from least to most privileged) |
---|---|
Delegated (work or school account) | LicenseAssignment.ReadWrite.All, User.ReadWrite.All, Directory.ReadWrite.All, |
Delegated (personal Microsoft account) | Not supported |
Application | LicenseAssignment.ReadWrite.All, User.ReadWrite.All, Directory.ReadWrite.All, |
Examples
Example 1: Assign a license to a user
Connect-Graph -Scopes User.ReadWrite.All, Organization.Read.All
$EmsSku = Get-MgSubscribedSku -All | Where SkuPartNumber -eq 'EMSPREMIUM'
Set-MgUserLicense -UserId '38955658-c844-4f59-9430-6519430ac89b' -AddLicenses @{SkuId = $EmsSku.SkuId} -RemoveLicenses @()
Id DisplayName Mail UserPrincipalName UserType
-- ----------- ---- ----------------- --------
38955658-c844-4f59-9430-6519430ac89b Bianca Pisani BiancaP@contoso.onmicrosoft.com Member
This example assigns a license from the EMSPREMIUM (ENTERPRISE MOBILITY + SECURITY E5) licensing plan to the unlicensed user 38955658-c844-4f59-9430-6519430ac89b. For more information, see assign licenses to users accounts with PowerShell.
Example 2: Assign more than one licenses to a user
Connect-Graph -Scopes User.ReadWrite.All, Organization.Read.All
$EmsSku = Get-MgSubscribedSku -All | Where SkuPartNumber -eq 'EMSPREMIUM'
$FlowSku = Get-MgSubscribedSku -All | Where SkuPartNumber -eq 'FLOW_FREE'
$addLicenses = @(
@{SkuId = $EmsSku.SkuId},
@{SkuId = $FlowSku.SkuId}
)
Set-MgUserLicense -UserId '38955658-c844-4f59-9430-6519430ac89b' -AddLicenses $addLicenses -RemoveLicenses @()
Id DisplayName Mail UserPrincipalName UserType
-- ----------- ---- ----------------- --------
38955658-c844-4f59-9430-6519430ac89b Bianca Pisani BiancaP@contoso.onmicrosoft.com Member
This example assigns EMSPREMIUM and FLOW_FREE licenses to the user 38955658-c844-4f59-9430-6519430ac89b.
Example 3: Assign a license to a user with some disabled plans
Connect-Graph -Scopes User.ReadWrite.All, Organization.Read.All
$EmsSku = Get-MgSubscribedSku -All | Where SkuPartNumber -eq 'EMSPREMIUM'
$disabledPlans = $EmsSku.ServicePlans | where ServicePlanName -in ("MFA_PREMIUM", "INTUNE_A") | Select -ExpandProperty ServicePlanId
$addLicenses = @(
@{SkuId = $EmsSku.SkuId
DisabledPlans = $disabledPlans
}
)
Set-MgUserLicense -UserId '38955658-c844-4f59-9430-6519430ac89b' -AddLicenses $addLicenses -RemoveLicenses @()
Id DisplayName Mail UserPrincipalName UserType
-- ----------- ---- ----------------- --------
38955658-c844-4f59-9430-6519430ac89b Bianca Pisani BiancaP@contoso.onmicrosoft.com Member
This example assigns EMSPREMIUM license with the MFA_PREMIUM and INTUNE_A services turned off.
Example 4: Update a license assigned to a user to add more disabled plans leaving the user's existing disabled plans in their current state
Connect-Graph -Scopes User.ReadWrite.All, Organization.Read.All
$EmsSku = Get-MgSubscribedSku -All | Where SkuPartNumber -eq 'EMSPREMIUM'
$userLicense = Get-MgUserLicenseDetail -UserId "38955658-c844-4f59-9430-6519430ac89b"
$userDisabledPlans = $userLicense.ServicePlans |
Where ProvisioningStatus -eq "Disabled" |
Select -ExpandProperty ServicePlanId
$newDisabledPlans = $EmsSku.ServicePlans |
Where ServicePlanName -in ("AAD_PREMIUM_P2", "AAD_PREMIUM") |
Select -ExpandProperty ServicePlanId
$disabledPlans = $userDisabledPlans + $newDisabledPlans | Select -Unique
$addLicenses = @(
@{SkuId = $EmsSku.SkuId
DisabledPlans = $disabledPlans
}
)
Set-MgUserLicense -UserId '38955658-c844-4f59-9430-6519430ac89b' -AddLicenses $addLicenses -RemoveLicenses @()
Id DisplayName Mail UserPrincipalName UserType
-- ----------- ---- ----------------- --------
38955658-c844-4f59-9430-6519430ac89b Bianca Pisani BiancaP@contoso.onmicrosoft.com Member
This example updates the EMSPREMIUM license assigned to the user to add AAD_PREMIUM_P2 and AAD_PREMIUM to the disabled services.
Example 5: Assign licenses to a user by copying the license assignment from another user
Connect-Graph -Scopes User.ReadWrite.All, Organization.Read.All
$mgUser = Get-MgUser -UserId '38955658-c844-4f59-9430-6519430ac89b'
Set-MgUserLicense -UserId "82f51c98-7221-442f-8329-3faf9fe022f1" -AddLicenses $mgUser.AssignedLicenses -RemoveLicenses @()
Id DisplayName Mail UserPrincipalName UserType
-- ----------- ---- ----------------- --------
82f51c98-7221-442f-8329-3faf9fe022f1 Mallory Cortez MalloryC@contoso.onmicrosoft.com Member
This examples copies the license assignment of user 38955658-c844-4f59-9430-6519430ac89b and assigns it to user 82f51c98-7221-442f-8329-3faf9fe022f1.
Example 6: Remove a license assigned to a user
Connect-Graph -Scopes User.ReadWrite.All, Organization.Read.All
$EmsSku = Get-MgSubscribedSku -All | Where SkuPartNumber -eq 'EMSPREMIUM'
Set-MgUserLicense -UserId "38955658-c844-4f59-9430-6519430ac89b" -AddLicenses @() -RemoveLicenses @($EmsSku.SkuId)
Id DisplayName Mail UserPrincipalName UserType
-- ----------- ---- ----------------- --------
38955658-c844-4f59-9430-6519430ac89b Bianca Pisani BiancaP@contoso.onmicrosoft.com Member
This example removes the EMSPREMIUM license assignment from the user.
Parameters
-AdditionalProperties
Additional Parameters
Parameter properties
Type: | System.Collections.Hashtable |
Supports wildcards: | False |
DontShow: | False |
Parameter sets
AssignViaIdentityExpanded
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
AssignExpanded
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
-AddLicenses
To construct, see NOTES section for ADDLICENSES properties and create a hash table.
Parameter properties
Type: | Microsoft.Graph.PowerShell.Models.IMicrosoftGraphAssignedLicense[] |
Supports wildcards: | False |
DontShow: | False |
Parameter sets
AssignViaIdentityExpanded
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
AssignExpanded
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
-BodyParameter
To construct, see NOTES section for BODYPARAMETER properties and create a hash table.
Parameter properties
Type: | Microsoft.Graph.PowerShell.Models.IComponents103UmuuRequestbodiesAssignlicenserequestbodyContentApplicationJsonSchema |
Supports wildcards: | False |
DontShow: | False |
Parameter sets
AssignViaIdentity
Position: | Named |
Mandatory: | True |
Value from pipeline: | True |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
Assign
Position: | Named |
Mandatory: | True |
Value from pipeline: | True |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
-Break
Wait for .NET debugger to attach
Parameter properties
Type: | System.Management.Automation.SwitchParameter |
Default value: | False |
Supports wildcards: | False |
DontShow: | False |
Parameter sets
(All)
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
-Confirm
Prompts you for confirmation before running the cmdlet.
Parameter properties
Type: | System.Management.Automation.SwitchParameter |
Supports wildcards: | False |
DontShow: | False |
Aliases: | cf |
Parameter sets
(All)
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
-Headers
Optional headers that will be added to the request.
Parameter properties
Type: | System.Collections.IDictionary |
Supports wildcards: | False |
DontShow: | False |
Parameter sets
(All)
Position: | Named |
Mandatory: | False |
Value from pipeline: | True |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
-HttpPipelineAppend
SendAsync Pipeline Steps to be appended to the front of the pipeline
Parameter properties
Type: | Microsoft.Graph.PowerShell.Runtime.SendAsyncStep[] |
Supports wildcards: | False |
DontShow: | False |
Parameter sets
(All)
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
-HttpPipelinePrepend
SendAsync Pipeline Steps to be prepended to the front of the pipeline
Parameter properties
Type: | Microsoft.Graph.PowerShell.Runtime.SendAsyncStep[] |
Supports wildcards: | False |
DontShow: | False |
Parameter sets
(All)
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
-InputObject
Identity Parameter To construct, see NOTES section for INPUTOBJECT properties and create a hash table.
Parameter properties
Type: | Microsoft.Graph.PowerShell.Models.IUsersActionsIdentity |
Supports wildcards: | False |
DontShow: | False |
Parameter sets
AssignViaIdentityExpanded
Position: | Named |
Mandatory: | True |
Value from pipeline: | True |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
AssignViaIdentity
Position: | Named |
Mandatory: | True |
Value from pipeline: | True |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
-Proxy
The URI for the proxy server to use
Parameter properties
Type: | System.Uri |
Supports wildcards: | False |
DontShow: | False |
Parameter sets
(All)
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
-ProxyCredential
Credentials for a proxy server to use for the remote call
Parameter properties
Type: | System.Management.Automation.PSCredential |
Supports wildcards: | False |
DontShow: | False |
Parameter sets
(All)
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
-ProxyUseDefaultCredentials
Use the default credentials for the proxy
Parameter properties
Type: | System.Management.Automation.SwitchParameter |
Default value: | False |
Supports wildcards: | False |
DontShow: | False |
Parameter sets
(All)
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
-RemoveLicenses
Add or remove licenses for the user to enable or disable their use of Microsoft cloud offerings that the company has licenses to. For example, an organization can have a Microsoft 365 Enterprise E3 subscription with 100 licenses, and this request assigns one of those licenses to a specific user. You can also enable and disable specific plans associated with a subscription. Direct user licensing method is an alternative to group-based licensing.
Permissions
Permission type | Permissions (from least to most privileged) |
---|---|
Delegated (work or school account) | LicenseAssignment.ReadWrite.All, User.ReadWrite.All, Directory.ReadWrite.All, |
Delegated (personal Microsoft account) | Not supported |
Application | LicenseAssignment.ReadWrite.All, User.ReadWrite.All, Directory.ReadWrite.All, |
Parameter properties
Type: | System.String[] |
Supports wildcards: | False |
DontShow: | False |
Parameter sets
AssignViaIdentityExpanded
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
AssignExpanded
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
-ResponseHeadersVariable
Optional Response Headers Variable.
Parameter properties
Type: | System.String |
Supports wildcards: | False |
DontShow: | False |
Aliases: | RHV |
Parameter sets
(All)
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
-UserId
The unique identifier of user
Parameter properties
Type: | System.String |
Supports wildcards: | False |
DontShow: | False |
Parameter sets
AssignExpanded
Position: | Named |
Mandatory: | True |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
Assign
Position: | Named |
Mandatory: | True |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
-WhatIf
Runs the command in a mode that only reports what would happen without performing the actions.
Parameter properties
Type: | System.Management.Automation.SwitchParameter |
Supports wildcards: | False |
DontShow: | False |
Aliases: | wi |
Parameter sets
(All)
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
Inputs
Microsoft.Graph.PowerShell.Models.IComponents103UmuuRequestbodiesAssignlicenserequestbodyContentApplicationJsonSchema
{{ Fill in the Description }}
Microsoft.Graph.PowerShell.Models.IUsersActionsIdentity
{{ Fill in the Description }}
System.Collections.IDictionary
{{ Fill in the Description }}
Outputs
Microsoft.Graph.PowerShell.Models.IMicrosoftGraphUser
{{ Fill in the Description }}
Notes
COMPLEX PARAMETER PROPERTIES
To create the parameters described below, construct a hash table containing the appropriate properties. For information on hash tables, run Get-Help about_Hash_Tables.
ADDLICENSES <IMicrosoftGraphAssignedLicense[]>: . [DisabledPlans <String[]>]: A collection of the unique identifiers for plans that have been disabled. IDs are available in servicePlans > servicePlanId in the tenant's subscribedSkus or serviceStatus > servicePlanId in the tenant's companySubscription. [SkuId <String>]: The unique identifier for the SKU. Corresponds to the skuId from subscribedSkus or companySubscription.
BODYPARAMETER <IComponents103UmuuRequestbodiesAssignlicenserequestbodyContentApplicationJsonSchema>
: .
[(Any) <Object>]: This indicates any property can be added to this object.
[AddLicenses <IMicrosoftGraphAssignedLicense[]>]:
[DisabledPlans <String[]>]: A collection of the unique identifiers for plans that have been disabled.
IDs are available in servicePlans > servicePlanId in the tenant's subscribedSkus or serviceStatus > servicePlanId in the tenant's companySubscription.
[SkuId <String>]: The unique identifier for the SKU.
Corresponds to the skuId from subscribedSkus or companySubscription.
[RemoveLicenses <String[]>]:
INPUTOBJECT <IUsersActionsIdentity>
: Identity Parameter
[UserId <String>]: The unique identifier of user