It can sometimes be useful to get a list of Office 365 users with a specific license type via PowerShell. Instead of logging into the Office 365 portal and using a filtered view in the admin center, you can do it straight from the command line.

  1. Connect to Office 365 via Powershell. If this cmdlet doesn’t work for you, follow this quick guide for instructions on installing the required PowerShell module.1Connect-MsolService

How to Install the Azure Active Directory PowerShell Module via PowerShell

  1. Open the Start menu on your computer and search for ‘Powershell’
  2. Right-click on Windows PowerShell and choose ‘Run as administrator’Run PowerShell As Administrator
  3. Type the following command and press enter.1Install-Module -Name MSOnline
  4. Type “Y” to install and import the NuGet providerInstall Azure Active Directory PowerShell Module with Install-Module MSOnline Cmdlet
  5. Type “Y” again to trust the providerAccept Terms and InstallAzure Active Directory PowerShell Module
  6. Wait for the package to install, then type the following to enter your Office 365 admin credentials and connect to Azure Active Directory via PowerShell:1Connect-MsolServiceRun Connect-MsolService To Connect to Azure Active Directory Powershell Module
  7. Once the Azure Active Directory PowerShell module has been installed, you only need to run the Connect-MsolService command to connect to the Azure AD service on this PC.
  1. Run Get-MsolAccountSku to get a list of the current licenses in your Office 365 tenant. Make a note of the AccountSkuId value for the license you want to filter on.1Get-MsolAccountSkuGet-MsolAccountSku Information
  2. Now you can edit this short script to get the users matching that license. In this case, we’re getting users with the EnterprisePremium license.1Get-MsolUser | Where-Object {($_.licenses).AccountSkuId -match "EnterprisePremium"}Get-MsolUser With Specific Office 365 LicenseReplace EnterprisePremium with the AccountSkuID you’re trying to filter by. Since we’re using the -match operator we don’t need to type the entire AccountSkuID, we can just type enough of it to ensure that we’re only retrieving that specific one.

Export these users to a text document

You can export these users to a text document using the Out-File cmdlet.

1Get-MsolUser | Where-Object {($_.licenses).AccountSkuId -match "EnterprisePremium"} | Out-file C:\temp\EnterprisePremiumUsers.csv

Export all licesensed users to file

Get-MsolUser -All | where {$_.isLicensed -eq $true} | select Displayname, userprinciplename,islicensed, {$.Licenses.AccountSuID}| Export-CSV C:\O365Userlist.csv -NoTypeInformation

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.