Edit

Share via


Set-AzureADUserLicense

Adds or removes licenses for a Microsoft online service to the list of assigned licenses for a user.

Note

The Set-AzureADUserLicense cmdlet is deprecated. Learn how to assign licenses with Microsoft Graph PowerShell. For more info, see the Assign License Microsoft Graph API.

Syntax

Default (Default)

Set-AzureADUserLicense
    -ObjectId <String>
    -AssignedLicenses <AssignedLicenses>
    [-InformationAction <ActionPreference>]
    [-InformationVariable <String>]
    [<CommonParameters>]

Description

The Set-AzureADUserLicense adds or removes licenses for a Microsoft online service to the list of assigned licenses for a user.

Examples

Example 1: Add a license to a user based on a template user

PS C:\> $LicensedUser = Get-AzureADUser -ObjectId "TemplateUser@contoso.com"
PS C:\> $User = Get-AzureADUser -ObjectId "User@contoso.com"
PS C:\> $License = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicense
PS C:\> $License.SkuId = $LicensedUser.AssignedLicenses.SkuId
PS C:\> $Licenses = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses
PS C:\> $Licenses.AddLicenses = $License
PS C:\> Set-AzureADUserLicense -ObjectId $User.ObjectId -AssignedLicenses $Licenses

The first command gets a user by using the Get-AzureADUser (./Get-AzureADUser.md)cmdlet, and then stores it in the $LicensedUser variable.

The second command gets another user by using Get-AzureADUser , and then stores it in the $User variable.

The third command creates an AssignedLicense type, and then stores it in the $License variable.

The fourth command set the SkuId property of $License to the same value as the SkuId property of $LicensedUser.

The fifth command creates an AssignedLicenses object, and stores it in the $Licenses variable.

The sixth command adds the license in $License to $Licenses.

The final command assigns the licenses in $Licenses to the user in $User. The licenses in $Licenses includes $License from the third and fourth commands.

Parameters

-AssignedLicenses

Specifies a list of licenses to assign or remove.

Parameter properties

Type:AssignedLicenses
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:True
Value from pipeline:True
Value from pipeline by property name:True
Value from remaining arguments:False

-InformationAction

Specifies how this cmdlet responds to an information event. The acceptable values for this parameter are:

  • Continue
  • Ignore
  • Inquire
  • SilentlyContinue
  • Stop
  • Suspend

Parameter properties

Type:ActionPreference
Default value:None
Supports wildcards:False
DontShow:False
Aliases:infa

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-InformationVariable

Specifies an information variable.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False
Aliases:iv

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-ObjectId

Specifies the ID of a user (as a UPN or ObjectId) in Azure AD.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:True
Value from pipeline:True
Value from pipeline by property name:True
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.

Notes

See the migration guide for Set-AzureADUserLicense to the Microsoft Graph PowerShell.