Find Users In Active Directory Department With PowerShell

In this blog post, I will show you how to find a group of users in Active Directory in a specific department and export them to a CSV file.

Active Directory Attributes

In Active Directory, a user department name or code is a value inside an attribute which in our case is the department attribute.

Code

To following code, will search for all users in a department and output the information to a .CSV file.

Get-ADUser -Filter 'department -like "Sales"' -Properties * | select name, UserPrincipalName,samaccountname,displayname | export-csv sales_users.csv -NoTypeInformation

Processing…
Success! You're on the list.

Posted

in

by