I’m looking to get all members of an AD group and sort users by manager. It would be even better if somehow we could pipe to out-file for either text file or csv, creating a separate file depending on who their manager is.
So if I have an AD group with 99 users and they’re split evenly between 3 managers, the output would be 3 txt or csv files, 1 for each manager that would list the 33 users under them.
Worth noting is that the “Manager” attribute on the AD-user is the managers distinguishedname.
So depending on the output you want, you may need some extra code (e.g. calling get-aduser with the manager DN).
Thank you Jarkko Vepsäläinen! This is just about exactly what I was looking for.
Just for background, our main goal was to create SCCM collections based on AD groups and we wanted to make groups per manager… he simultaneously burst my bubble and blew my mind as we were able to create query based collections querying the manager attribute in AD.
Thank you very much though as this will help in the future.
Just a heads up, you are working on the assumption that your groups contain only users, and that your managers are all users. It is better to use get-adobject, confirm the object type if necessary, or skip them if not relevant.