Get a distinct list of departments from the active directory

Dear Experts,

In our big hospital we have Active Directory with about 12000 user accounts and about 100 departments.
I've got a view account that successfully queries the AD.
The maximal number of records I can retrieve from the Ldap has been limited (by default) to 999 so enumerating all 12000 users is not an option. And removing the limit is not permitted and not desired.

What I would like to get from the AD is all the distinct entries in the user field "department".
Is there a "distinct" option in LDAP queries?

Regards,

Steynsk
LVL 1
SteynskAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

FOXActive Directory/Exchange EngineerCommented:
launch powershell as an administrator
import-module activedirectory
get-aduser -filter * -property department | select department | sort-object department -unique

Or did you want all users in each department?
FOXActive Directory/Exchange EngineerCommented:
Steynsk,
launch powershell as an administrator
type import-module activedirectory (press enter)
I have attached the script you will need. Before you run it:
1.edit it with your domain name in the searchbase
2. Rename it from .txt to .ps1 this forum doesn't allow .ps1 attachments
3. Save it to a location of your choice
4. Navigate to the path of that location and run

.\departmentbrkdown.ps1 | Output-file c:\temp\departmentreport.csv  

 (or wherever you choose to save the file)
departmentbrkdown.txt

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SteynskAuthor Commented:
thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Active Directory

From novice to tech pro — start learning today.