How to List Active Directory Users by Department

In this guide, I’ll show you how to list Active Directory users by Department. I will include examples for both Active Directory and Azure Active Directory.

Topics in this article

Let’s get started.

List Active Directory Users by Department with PowerShell

In this example, I’ll display all users and list only the displayname and department attributes.

get-aduser -filter * -properties displayname, department | select displayname, department
list active directory users by department powershell

Get a Count of AD Users in each Department

In this example, I’ll get all departments and the count of users in each department. This is useful to see how many users you have in each department.

get-aduser -filter * -properties * | group-object -property department
powershell count of users in each department

Search for Users in a Specific Department

To get users from a specific department you can use the -filter parameter.

In this example, I’ll list all users that are in the “Accounting” department.

Get-ADUser -Filter {department -eq "Accounting"} -property department | Select samaccountname, department
powershell search for users in specific department

List AD Users by Department with GUI Tool

An alternative to PowerShell is to use a graphical tool that doesn’t require any scripting. In this example, I’ll use the AD Pro Toolkit to get all users and their departments.

Open the toolkit, Click on Export Users and click Run.

By default, this tool will display several user attributes including the OU and group membership.

toolkit list users by department

You can add or remove user attributes by clicking the columns button.

To export the results to CSV click the export button.

toolkit export users

List Azure Users by Department

To list Azure users by department we will use the Get-MgUser PowerShell cmdlet.

This cmdlet requires the Microsoft graph module to be installed. To learn more about this refer to the article get-mguser all properties.

Below is the command to list Azure users by the department.

get-mguser -All -Property displayname, department | select displayname, department
azure list users by department

Get Azure Users in Specific Departments

In this example, I’ll search for Azure users in the Accounting department.

get-mguser -filter "department eq 'Accounting'" -Property displayname, department | select displayname, department
azure search users in specific department

I hope you enjoyed this article. If you have questions post them below.

Related Content

Get-ADUser filter examples

PowerShell Get Disabled Users

How to find bad password attempts in Active Directory

Leave a Comment