Assign licenses to user accounts with Office 365 PowerShell

Summary: Explains how to use Office 365 PowerShell assign an Office 365 license to unlicensed users.

Licensing user accounts in Office 365 is important, because users can't use any Office 365 services until their account has been licensed. You can use Office 365 PowerShell to efficiently assign licenses to unlicensed accounts, especially multiple accounts.

Before you begin

  • The procedures in this topic require you to connect to Office 365 PowerShell. For instructions, see Connect to Office 365 PowerShell.

  • Use the Get-MsolAccountSku cmdlet to view the available licensing plans and the number of available licenses in each plan in your organization. The number of available licenses in each plan is ActiveUnits - WarningUnits - ConsumedUnits. For more information about licensing plans, licenses, and services, see View licenses and services with Office 365 PowerShell.

  • To find the unlicensed accounts in your organization, run the command Get-MsolUser -All -UnlicensedUsersOnly

  • You can assign licenses only to user accounts that have the UsageLocation property set to a valid ISO 3166-1 alpha-2 country code. For example, US for the United States, and FR for France. Some Office 365 services aren't available in certain countries. For more information, see About license restrictions.

    To find accounts that don't have a UsageLocation value, run the command Get-MsolUser -All | where {$_.UsageLocation -eq $null}. To set the UsageLocation value on an account, use the syntax Set-MsolUser -UserPrincipalName "<Account>" -UsageLocation <CountryCode>. For example, Set-MsolUser -UserPrincipalName "" -UsageLocation US.

  • If you use the Get-MsolUser cmdlet without using the -All parameter, only the first 500 accounts are returned.

Assigning licenses to user accounts

To assign a license to a user, use the following syntax in Office 365 PowerShell:

Set-MsolUserLicense -UserPrincipalName "<Account>" -AddLicenses "<AccountSkuId>"

This example assigns a license from the litwareinc:ENTERPRISEPACK (Office 365 Enterprise E3) licensing plan to the unlicensed user

Set-MsolUserLicense -UserPrincipalName "" -AddLicenses "litwareinc:ENTERPRISEPACK"

To assign a license to many unlicensed users, use the following syntax:

$x = Get-MsolUser -All -UnlicensedUsersOnly [<FilterableAttributes>]; $x | foreach {Set-MsolUserLicense -AddLicenses "<AccountSkuId>"}


  • You can't assign multiple licenses to a user from the same licensing plan.

  • If you don't have enough available licenses, the licenses are assigned to users in the order that they're returned by the Get-MsolUser cmdlet until the available licenses run out.

This example assigns licenses from the litwareinc:ENTERPRISEPACK (Office 365 Enterprise E3) licensing plan to all unlicensed users.

$AllUn = Get-MsolUser -All -UnlicensedUsersOnly; $AllUn | foreach {Set-MsolUserLicense -AddLicenses "litwareinc:ENTERPRISEPACK"}

This example assigns those same licenses to unlicensed users in the Sales department in the United States.

$USSales = Get-MsolUser -All -Department "Sales" -UsageLocation "US" -UnlicensedUsersOnly; $USSales | foreach {Set-MsolUserLicense -AddLicenses "litwareinc:ENTERPRISEPACK"}

New to Office 365?


LinkedIn logo New to Office 365?

Discover free video courses for Office 365 admins and IT pros, brought to you by LinkedIn Learning.

See also

See the following additional topics about managing users with Office 365 PowerShell:

For more information about the cmdlets that are used in these procedures, see the following topics: