Home » Office 365 » Get Office 365 Users with License Type with PowerShell

Get Office 365 Users with License Type with PowerShell

To get Office 365 users with a specific license type with PowerShell, you can follow these steps:

Step 1: Import the Microsoft Azure Active Directory Module for Windows PowerShell.

Import-Module MSOnline

Step 2: Connect to Office 365 with PowerShell.

Connect-MsolService

The above command will prompt you to sign in to your account. If the above command doesn’t work or throws any error message, read Connect to Office 365 with PowerShell (step-by-step guide).

Step 3: Get the list of licenses in your Office 365 tenant using the Get-MsolAccountSku cmdlet.

Get-MsolAccountSku

The above command will return a list of licenses. The AccountSkuId property value specifies the license name.

Get a list of current licenses in your Office 365
Get a list of current licenses in your Office 365

Step 4: Run the following command to get Office 365 users with the Enterprise E3 license.

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

In the PowerShell script, the Get-MsolUser command gets a list of all users in Office 365 and pipes them to the Where-Object cmdlet. The Where-Object command checks for the user account AccountSkuId to match the “ENTERPRISEPACK” license type.

This command outputs a list of all 365 users with the Enterprise E3 license.

Office 365 Users with Enterprise E3 License Type
Office 365 Users with Enterprise E3 License Type

Run the following command to get Office 365 users with EnterprisePremium license type.

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

The above command returns all the users with Office 365 E5 license type assigned to them.

Step 5: To export the Office 365 users with a specific license type to a CSV file, you would run the following command.

Get-MsolUser | Where-Object {($_.licenses).AccountSkuId -match "ENTERPRISEPACK"} | Export-Csv -Path D:\PS\EnterprisePackUsers.csv -NoTypeInformation

This command would export a list of all Office 365 users with Enterprise E3 license type to a CSV file.

Cool Tip: How to view all available licenses using the Get-MsolAccountSku in PowerShell!

Conclusion

I hope the above article on how to get Office 365 users with a specific license type is helpful to you.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.