Problem Statement:

How do I get list of all users from my M365 tenant based on filter conditions like Country, Department


One of the frequently used task of an Office 365 administrator is to deal with users list. 

You can use the M365 admin center or Azure Portal to get list of all the users but currently there is no option to apply filter based on your requirement. 

For example if I want to get the list of all the users who belongs to "Department = HR",  then I have to export all the users to an excel sheet and then apply filter in the excel on Department Column. This can be a tedious task if you have huge number of users in your tenant. 

In this article we will see how we can get the users based on certain filter condition using PowerShell and using CoreView.

1. PowerShell to get the List of Users based on certain Filter Condition:

To be able to use the Azure AD cmdlets first you would need to install and import Azure AD modules. For more info kindly refer Connect with Azure AD

Install-Module AzureAD
Import-Module AzureAD

Once you have completed the above steps and made successful connection with Azure AD you can use various cmdlets to get Azure AD users based on certain filter conditions.


# Displays full list of User accounts
Get-AzureADUser -Filter "startswith(JobTitle,'Sales')"
# This command gets all the users whose job title starts with sales e.g Sales Manager and Sales Assistant.
Get-AzureADUser -Filter "Department eq 'HR'"
# This command gets all the users whose Department is HR
Get-AzureADUser -Filter "Country eq 'India'"
# This command gets all the users whose country equals to India
Although this is helpful in most scenarios it has certain restrictions when applying the filter conditions on certain properties. For example we cannot use same script to get all the users of a particular domain or users of particular licensed assigned.

2. Use of CoreView to retrieve users based on various filter conditions.

Using CoreView you can apply filter on Users list based on tons of parameter. Lets see the steps to achieve this.

  • Login to CoreView 
  • Select Reports > Users > Active Users

  • This will show all the users available in the tenant.
  • Now you can click on columns and choose all the columns that you want to get the information for and use it later for applying the filter condition.
  • Click on apply.
  • This will load the Users report with all the selected columns.
  • Now you can apply filter based on your requirements. For example, if you want to apply filter to see all the users belongs to a particular domain then simply use Domain contains 'domain name'. You can also use Domain equals 'domain name' and it will be displayed all the users that belongs to that domain.

Similarly you can apply filter on any column based on your requirement and export the filtered values to an excel or perform any action on them directly from the report.