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
- List Active Directory Users by Department with PowerShell
- Get a Count of AD Users in each Department
- Search for AD Users in a Specific Department
- List AD Users by Department with GUI Tool
- Get Azure Users by Department
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
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
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
Easily List AD Users by Department with AD Pro Toolkit
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.
You can add or remove user attributes by clicking the columns button.
To export the results to CSV click the export button.
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
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
I hope you enjoyed this article. If you have questions post them below.