Set-​Azure​AD​User​License

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

Syntax

Set-AzureADUserLicense
   -AssignedLicenses <AssignedLicenses>
   [-InformationAction <ActionPreference>]
   [-InformationVariable <String>]
   -ObjectId <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 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 commmand 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.

Required Parameters

-AssignedLicenses

Specifies a list of licenses to assign or remove.

Type:AssignedLicenses
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName, ByValue)
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
Accept pipeline input:True (ByPropertyName, ByValue)
Accept wildcard characters:False

Optional Parameters

-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
Accept pipeline input:False
Accept wildcard characters:False
-InformationVariable

Specifies an information variable.

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