Scripting Office365 User Licenses

Ever needed to quickly get information on your Office 365 licenses? Use the following Azure PowerShell cmdlets:

To get an overview of all licenses in the tenant:

Get-MsolUser | FL DisplayName, Licenses

Not the best output but it will work. You can substitute FL with FT to turn it into a table, but that will leave you with truncated names, which isn’t the best either.

To get all Office 365 users that have a specific license, such as an E5:

Get-MsolUser | FL DisplayName, Licenses | Where-Object {$_.Licenses.AccountSkuID -eq “office365man:E5” }

To get all unlicensed users (using PowerShell):

Get-MSOLUser –UnlicensedUsersOnly

To add a license to a user:

Set-MsolUserLicense -userprincipalname –AddLicenses office365man:E5

To remove an existing license from a user:

Set-MsolUserLicense -userprincipalname –RemoveLicenses office365man:E5

In addition, you can also create your custom licensing schema using the New-MSOLLicenseOptions cmdlet. Let’s create a Sway-only license (just because we can)

The first step is find the service plans in available SKU’s:


Available licenses per SKU
Available licenses per SKU

Next, create a new License configuration using New-MSOLLicenseOptions and disabling every service plan item you don’t want in the new license (please note, you create the license temporarily and store it in a PowerShell variable. You cannot create your own sku).


Now, you can assign the license to your users:

Get-MsolUser -UserPrincipalName | Set-MsolUserLicense -licenseoptions $SwayOnlyLicense

The end-result is shown in the WUI:

Effective user service plans
Effective user service plans
Leave a reply

Your email address will not be published. Required fields are marked *