Query Entra ID for users matching a role or organizational unit using Graph filters.
Complexity: Beginner. Impact: read-only + reporting + user-management + directory-query.
Why use this workflow
IT admins frequently need to pull scoped lists of users, for example all engineers, everyone in Finance, or staff with a specific title pattern. Scrolling the Entra admin center is slow and error-prone, especially in tenants with thousands of users. The Microsoft Graph $filter query parameter on the /users endpoint lets you target users precisely by jobTitle, department, or other directory attributes.
Common scenarios include:
- Building a distribution list or security group for a role-based audience
- License reviews scoped to a department
- Identifying users for targeted Conditional Access or MFA rollouts
- Generating reports for HR, compliance, or management
Expected outcomes
- A filtered list of users matching a given job title, title prefix, or department
- Selected attributes for each user (id, displayName, UPN, jobTitle, department)
- A reusable query pattern that you can adapt to any directory attribute exposed by Graph
- Optional exported results as CSV for downstream workflows
Risks and considerations
Things to be aware of
- Data quality: Filters are only as good as the attribute data. If HR has not populated
jobTitleordepartmentconsistently, results are incomplete. - Case sensitivity:
eqfilters can miss case variations such as "engineer" and "Engineer". Usestartswithor normalize your input to catch them. - Advanced query flags: Some filter operators (like
endsWith,$count, and$searchon directory objects) require theConsistencyLevel: eventualheader and$count=true. - Paging: Large result sets return an
@odata.nextLink. Scripts must follow paging or they miss users. - Privacy: Exported user lists contain PII. Store and share them according to your data handling policy.
- Guest users: External (B2B) guests may also match. Add
userType eq 'Member'to the filter if you want employees only.
Required permissions
| Permission | Why it's needed |
|---|---|
| User.Read.All | Required to read directory user profiles including jobTitle and department |
| Directory.Read.All | Alternative, broader read access to directory objects if User.Read.All is not granted |
Ask Dex
Paste the prompt into a Dex conversation.
Prompt for IT admins
List all users in our tenant with the job title {job_title} or in the {department} department. Return name, UPN, job title, and department, and export the results as CSV.
Manual steps (admin center)
The Entra admin center supports ad hoc filtering of the users list, which is useful for quick lookups without writing a query.
- Sign in to the Microsoft Entra admin center as a user with at least the Directory Readers role.
- Go to Identity > Users > All users.
- Select Add filter above the user list.
- Choose Job title (or Department) from the property list.
- Enter the value to match, for example
EngineerorEngineering, and select Apply. - The grid now shows only matching users. Use Columns to add Job title and Department so they are visible.
- (Optional) Select Download users to export the filtered set as CSV.
Notes
- For complex multi-attribute queries (for example, Engineering department and enabled accounts), use Graph or PowerShell instead.
Microsoft Graph API
Use the /users endpoint with $filter and $select to target users and return only the fields you need.
Basic: exact job title match
GET https://graph.microsoft.com/v1.0/users?$filter=jobTitle eq 'Engineer'&$select=id,displayName,userPrincipalName,jobTitle,departmentCombined: title prefix or department
GET https://graph.microsoft.com/v1.0/users?$filter=startswith(jobTitle,'Engineer') or department eq 'Engineering'&$select=id,displayName,userPrincipalName,jobTitle,departmentSample response
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users",
"value": [
{
"id": "8f2d3187-5fad-4d73-a9f5-3c356e68a038",
"displayName": "Alex Example",
"userPrincipalName": "AlexE@contoso.onmicrosoft.com",
"jobTitle": "Software Engineer",
"department": "Engineering"
}
]
}Advanced filters (require eventual consistency)
For endsWith, $count, or $search on directory objects, add the ConsistencyLevel header:
GET https://graph.microsoft.com/v1.0/users?$filter=endsWith(jobTitle,'Engineer')&$count=true&$select=id,displayName,jobTitle
ConsistencyLevel: eventualPaging
If the response contains @odata.nextLink, issue a GET to that URL to retrieve the next page. Continue until no nextLink is present.
Useful variants
$filter=department eq 'Engineering' and accountEnabled eq true: only enabled accounts$filter=department eq 'Engineering' and userType eq 'Member': exclude guests$orderby=displayName: sort results (may requireConsistencyLevel: eventualwhen combined with$filter)
PowerShell
The Microsoft.Graph module wraps the same /users endpoint and handles paging automatically with -All.
1. Install and connect
Install-Module Microsoft.Graph -Scope CurrentUser
Connect-MgGraph -Scopes "User.Read.All"2. Filter by job title or department
# Exact job title match
Get-MgUser -Filter "jobTitle eq 'Engineer'" -Property Id,DisplayName,UserPrincipalName,JobTitle,Department
# Title prefix or department, return all pages
Get-MgUser -Filter "startswith(jobTitle,'Engineer') or department eq 'Engineering'" `
-Property Id,DisplayName,UserPrincipalName,JobTitle,Department `
-All |
Select-Object DisplayName,UserPrincipalName,JobTitle,Department3. Export to CSV
Get-MgUser -Filter "department eq 'Engineering'" -All `
-Property Id,DisplayName,UserPrincipalName,JobTitle,Department |
Select-Object DisplayName,UserPrincipalName,JobTitle,Department |
Export-Csv -Path ".\engineers.csv" -NoTypeInformationNotes
- Use
-ConsistencyLevel eventual -CountVariable cfor advanced filters (endsWith,$count). - Run
Disconnect-MgGraphwhen finished on shared machines.