Assign Office 365 license via PowerShell

You can assign a license to a user using the Microsoft Portal, just select the user and in the Action Pane select License. Depending on the licenses you got available you can assign it (in this example an E3 license) and set the user’s location (in this example Netherlands):


This is ok if you want to assign only one user license, if you want to assign a license to a group of users you can also user PowerShell (with the Windows Azure Active Directory module) to accomplish this.

To retrieven licensing information you have to setup a connection with Microsoft Online and use the Get-MsolAccountSku command:

$Cred = Get-Credential

Connect-MSOLService –Credential $Cred



So in this (demo) environment we have 25 licenses available for this organization. The license is assigned to a user using the Set-MsolUserLicense, but if you do an error is raised:

“Set-MsolUserLicense: You must provide a required property: Parameter name: UsageLocation” as shown in the following screenshot:


You have to set the User Location (as can be seen in the GUI) and to achieve this you have to use the Set-MsolUser command. When the User Location is set you can assign a license:


You can combine the two commands in just one line using the pipe feature:

Get-MsolUser –UserPrincipalName | Set-MsolUser –UsageLocation NL | Set-MsolUserLicense –AddLicenses “amsio365:ENTERPRISE”

When you check the Microsoft Portal you’ll see the license is assigned:


Especially when you have a lot of users this can be very useful.

3 thoughts on “Assign Office 365 license via PowerShell”

    1. ## create csvfile UserprincipalName
      $collection = Import-Csv -Path C:\Users\myuser\Desktop\users.csv
      foreach ($item in $collection) {

      Set-MsolUser -UserPrincipalName $item.login -UsageLocation US
      Set-MsolUserLicense -UserPrincipalName $item.login -AddLicenses lic001:Xxxxweeww


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your 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 )

Google+ photo

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

Connecting to %s