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):

image

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

Get-MsolAccountSku

image

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:

image

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:

image

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

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

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

image

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
      }

      Like

Leave a comment