Link to home
Start Free TrialLog in
Avatar of OasisEE
OasisEE

asked on

Powershell command to Pull "Display Name" "Job Title" "Department" "Manager" and "Direct Reports" for each user

Hey guys, I need a little help crafting a powershell command to pull "Display Name" "Job Title" "Department" "Manager" and "Direct Reports" for each user and dump into a csv.  I found some resources on the web but cannot find one that does the above.
Avatar of Will Szymkowski
Will Szymkowski
Flag of Canada image

Use the following script below...
Import-module activedirectory
Get-AdUser -Filter * -Properties DisplayName, Title, Department, Manager |
Export-csv "c:\filename.csv" -nti
 

Open in new window


Will.
Avatar of OasisEE
OasisEE

ASKER

Hi will.  Thanks for answering so fast. What about the direct reports?
With PowerShell, the first step always is to get the correct cmdlet, in this case get-aduser. With that, the next step always is to get all properties and check which one you want:
get-aduser myuser -Properties * | fl *

Open in new window

In that list you should now see all available properties and their value, which helps in deciding whether it is the right one. You can also look at a restricted set, e.g. everything with "name" in it:
get-aduser myuser -Properties * | fl *name*

Open in new window

The command for everything but "Direct Reports" is
get-aduser -filter * -Properties * | select DisplayName, Title, Department, Manager | export-csv -NoType c:\results.csv

Open in new window

I cannot find anything that fits for "Direct Reports", that seems to be no standard AD attribute, but introduced by an AD Schema extension.
Import-module activedirectory
Get-AdUser -Filter * -Properties DisplayName, Title, Department, Manager | Select DisplayName, Title, Department, Manager
Export-csv "c:\filename.csv" -nti

Open in new window


Unfortunately Direct Reports is not an attribute of Get-AdUser cmdlet.

I have modified the original script to add the select portion as I forgot to add this in the original.

Will.
If for some reason powershell is not working exactly as you would like. There is a native program that does exactly what you are asking for, CSVDE. It creates CSV files from AD data.
ASKER CERTIFIED SOLUTION
Avatar of OasisEE
OasisEE

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of OasisEE

ASKER

Well, this is kinda weird.  I get to rate myself.  In that case, A+! ;)