New day, new PowerShell Magic….
One of the customer manger has contacted us with the below requirement:
- Export particular attributes for Direct reports from multiple managers.
- Input will be provided via samacountnames of managers thru text file.
Attribute List:
Manager,FirstName, LastName, EmailAddress,Department, Location, Employeeid
We have used PowerShell Active Directory Module to achieve this as it has DirectReports attribute that we can loop thru.
Line 160 of Script:
$directrports = Get-ADUser -id $user -Properties directreports | Select -ExpandProperty directreports
Download/Install the script from PowerShell Gallery or from GitHub.
Once installed, you will be able to find the script in below location , you can run from there or copy it to some other location.
C:\Program Files\WindowsPowerShell\Scripts
Now when you run it, it will prompt you for the input text file which contains managers samaccountnames.
text file contents:
samaccountname1
samaccountname2
samaccountname3
samaccountname4
It will also create report and logs folder, report will be generated in CSV form and will be saved in report folder.

You can modify the script , add other attributes as per your requirement by updating the code between line 162 to 171.
I will upload the solution to Technet Script Gallery as well in coming week, as of now gallery is not opening correctly in browser and upload is not working.
This is excellent. How can I use it to query Global Catalog or different domains in a forrest?
you can do that by updating the -server parameter, here is the hint
https://techwizard.cloud/2018/11/22/powershell-tip-add-members-to-a-group-in-different-domain/