Office 365 – Assigning licenses to users using PowerShell

Requirement

I needed to assign Office 365 licenses to multiple users, this article explains how to assign licenses to Office 365 users using PowerShell.

Configuration

First you need to connect to the relevant Office 365 Tenant using PowerShell.  I am assuming you have the required software installed (64-bit versions of the Microsoft Online Services Sign-in Assistant & Microsoft Azure Active Directory Module).  If not see Connect to Office 365 PowerShell.

Launch Windows Azure Active Directory Module and run the following commands.

$credential=Get-Credential

Office365_Credentials

Connect-MsolService -Credential $credential

Office365_ConnectMSOL

Available Licenses

To determine the name of the license(s) you need to assign, run the following command.

Get-MsolAccountSku

Office365_AccountSkuId

We need the AccountSkuId value, this will be TenantName: followed by the Office 365 Service Plan SKU.  In the screenshot above, MCOSTANDARD translates to a Skype for Business (Plan 2) license.

ActiveUnits gives you the number of licenses issued to the Tenant (110), and from ConsumedUnits (110) you can see all licenses are allocated.

Licensing a Single User

You have to assign a usage location to the user, I am in the United Kingdom (GB), so it’s as follows:

Set-MsolUser -UserPrincipalName [UPN] -UsageLocation GB

For example:

Set-MsolUser -UserPrincipalName steve.bush@x500.co.uk -UsageLocation GB

Note if you skip the above step and try to assign the license first you’ll get the following error: Set-MsolUserLicense : A parameter cannot be found that matches parameter name ‘UsageLocation’.

Now the license can be assigned:

Set-MsolUserLicense -UserPrincipalName [UPN] -AddLicenses “LICENSE”

For example:

Set-MsolUserLicense -UserPrincipalName steve.bush@x500.co.uk -AddLicenses “x500365:MCOSTANDARD”

Licensing Multiple Users

Create a CSV file containing the following for each user: UserPrincipalName (UPN column), the Office 365 license to apply (License column), and UsageLocation (Location column).

Office365_PowerShell_CSV

$users = Import-CSV users-to-license.csv

$users | ForEach {
Set-MsolUser -UserPrincipalName $_.UPN -UsageLocation $_.Location
Set-MsolUserLicense -UserPrincipalName $_.UPN -AddLicenses $_.License
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s