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

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 "[email protected]"  
PS C:\> $User = Get-AzureADUser -ObjectId "[email protected]"  
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 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.

Type:AssignedLicenses
Position:Named
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-InformationAction

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

  • Continue
  • Ignore
  • Inquire
  • SilentlyContinue
  • Stop
  • Suspend
Type:ActionPreference
Aliases:infa
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-InformationVariable

Specifies an information variable.

Type:String
Aliases:iv
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-ObjectId

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

Type:String
Position:Named
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False