Find Office 365 users with a specific license via Powershell

If you want to get a list of Office 365 users with a specific license type you could go to the license overview in the portal and check your licenses there. Simply select the license you are interested in.

O365 portal license overview

This will list the users on your screen. There is an export button on top if you want to export the shown data.

O365 export users

To do the same via Powershell and get a nicely formatted export or do more fancy things you do the following.

Connect to Office 365 via Powershell. If this doesn’t work, please follow the installation instructions.

Connect-MsolService

Get a list of the licenses in your Office 365 tenant:

Get-MsolAccountSku

This will provide an overview comparable to what you can find in the portal.

O365 msolaccountsku

Please note that the AccountSkuId is the internal name of the license. It does not match the commercial name of the license. Here are a few common names and their translations:

AccountSkuIdCommercial name
STANDARDPACKOFFICE 365 E1
ENTERPRISEPACKOFFICE 365 E3
ENTERPRISEPREMIUMOFFICE 365 E5
DESKLESSPACKOFFICE 365 F3
EXCHANGESTANDARDEXCHANGE ONLINE (PLAN 1)

To get the desired list of users with a certain license, you need to look up the AccountSkuId in your overview and provide it like this:

Get-MsolUser -All | Where-Object {($_.licenses).AccountSkuId -match "ENTERPRISEPACK"}

Replace ENTERPRISEPACK with (unique part of) the AccountSkuID you’re trying to filter by.