| title | Set-EntraBetaUserLicense |
|---|---|
| description | This article provides details on the Set-EntraBetaUserLicense command. |
| ms.topic | reference |
| ms.date | 07/26/2024 |
| ms.author | eunicewaweru |
| ms.reviewer | stevemutungi |
| manager | CelesteDG |
| author | msewaweru |
| external help file | Microsoft.Graph.Entra.Beta-Help.xml |
| Module Name | Microsoft.Graph.Entra.Beta |
| online version | https://learn.microsoft.com/powershell/module/Microsoft.Graph.Entra.Beta/Set-EntraBetaUserLicense |
| schema | 2.0.0 |
Adds or removes licenses for a Microsoft online service to the list of assigned licenses for a user.
Set-EntraBetaUserLicense
-UserId <String>
-AssignedLicenses <AssignedLicenses>
[<CommonParameters>]The Set-EntraBetaUserLicense adds or removes licenses for a Microsoft online service to the list of assigned licenses for a user.
For delegated scenarios, the calling user needs at least one of the following Microsoft Entra roles.
- Directory Writers
- License Administrator
- User Administrator
Note: Before assigning a license, assign a usage location to the user using:
Set-EntraUser -ObjectId user@contoso.com -UsageLocation '<two-letter-country-code e.g. GB/US>'.
Connect-Entra -Scopes 'User.ReadWrite.All'
$LicensedUser = Get-EntraBetaUser -UserId 'TemplateUser@contoso.com'
$License = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicense
$License.SkuId = $LicensedUser.AssignedLicenses.SkuId
$Licenses = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses
$Licenses.AddLicenses = $License
$Params = @{
UserId = 'SawyerM@contoso.com'
AssignedLicenses = $Licenses
}
Set-EntraBetaUserLicense @ParamsName Value
---- -----
externalUserStateChangeDateTi…
businessPhones {8976546787}
postalCode 444601
createdDateTime 06-11-2023 04:48:19
surname KTETSs
jobTitle Manager
employeeType
otherMails {SawyerM@contoso.com}
isResourceAccount
usageLocation DE
legalAgeGroupClassification Adult
id cccccccc-2222-3333-4444-dddddddddddd
isLicenseReconciliationNeeded False
This example demonstrates how to assign a license to a user based on a template user.
-UserIdparameter specifies the Id of a user(as a UserPrincipalName or UserId).-AssignedLicensesparameter specifies a list of licenses to assign or remove.
Connect-Entra -Scopes 'User.ReadWrite.All'
$LicensedUser = Get-EntraBetaUser -UserId 'AdeleV@contoso.com'
$User = Get-EntraBetaUser -UserId 'SawyerM@contoso.com'
$License1 = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicense
$License1.SkuId = $LicensedUser.AssignedLicenses.SkuId[0]
$License2 = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicense
$License2.SkuId = $LicensedUser.AssignedLicenses.SkuId[1]
$addLicensesArray = @()
$addLicensesArray += $License1
$addLicensesArray += $License2
$Licenses = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses
$Licenses.AddLicenses = $addLicensesArray
$Params = @{
UserId = $User.UserId
AssignedLicenses = $Licenses
}
Set-EntraBetaUserLicense @ParamsName Value
---- -----
externalUserStateChangeDateTi…
businessPhones {8976546787}
postalCode 444601
createdDateTime 06-11-2023 04:48:19
surname KTETSs
jobTitle Manager
employeeType
otherMails {SawyerM@contoso.com}
isResourceAccount
usageLocation DE
legalAgeGroupClassification Adult
id cccccccc-2222-3333-4444-dddddddddddd
isLicenseReconciliationNeeded False
This example demonstrates how to assign a license to a user by copying license from another user.
-UserIdparameter specifies the Id of a user(as a UserPrincipalName or UserId).-AssignedLicensesparameter specifies a list of licenses to assign or remove.
Connect-Entra -Scopes 'User.ReadWrite.All'
$UserPrincipalName = 'SawyerM@contoso.com'
$User = Get-EntraBetaUser -UserId $UserPrincipalName
$SkuId = (Get-EntraBetaUserLicenseDetail -UserId $UserPrincipalName).SkuId
$Licenses = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses
$Licenses.RemoveLicenses = $SkuId
Set-EntraBetaUserLicense -UserId $User.UserId -AssignedLicenses $LicensesName Value
---- -----
displayName SawyerM
id cccccccc-2222-3333-4444-dddddddddddd
jobTitle
surname M
mail
userPrincipalName SawyerM@contoso.com
mobilePhone
preferredLanguage
@odata.context https://graph.microsoft.com/v1.0/$metadata#users/$entity
businessPhones {}
officeLocation
givenName Sawyer
This example demonstrates how to remove a user's license by retrieving the user details.
-UserIdparameter specifies the Id of a user(as a UserPrincipalName or UserId).-AssignedLicensesparameter specifies a list of licenses to assign or remove.
Specifies a list of licenses to assign or remove.
Type: AssignedLicenses
Parameter Sets: (All)
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName, ByValue)
Accept wildcard characters: FalseSpecifies the ID of a user (as a UserPrincipalName or UserId) in Microsoft Entra ID.
Type: System.String
Parameter Sets: (All)
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName, ByValue)
Accept wildcard characters: FalseThis cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.