Link to home
Start Free TrialLog in
Avatar of P S
P S

asked on

How to get displayname from manager attribute

Basically. i've a text file with bunch of samaccountnames and my task is to get firstname, lastname,email address and manager name out of those samaccountnames. I was able to write below script and 95% job is done but i can't seem to get manager name properly. Below is what i wrote

GC C:\temp\Test.txt| % {Get-Aduser $_ -Pr * | Select GivenName,Surname,displayname,manager} | export-csv C:\temp\Test/csv

but I can't seem to get the display name of the manager. It's coming up similar to Distinguish name attribute.

Any help would be much appreciated

Thanks in advance..
Avatar of oBdA
oBdA

The "Manager" attribute will contain the manager's DN; you need a calculated property to get the display name on the fly:
Get-Content -Path C:\temp\Test.txt |
	ForEach-Object {
		Get-Aduser -Identity $_ -Properties 'GivenName', 'Surname', 'DisplayName', 'Manager' |
		Select-Object `
			'GivenName',
			'Surname',
			'DisplayName',
			@{Name='Manager'; Expression={If ($_.Manager) {(Get-Aduser -Identity $_.Manager -Properties DisplayName).DisplayName} Else {''}}}
	} | Export-Csv -Path C:\temp\Test.csv -NoTypeInformation

Open in new window

Avatar of P S

ASKER

Thanks oBdA. It worked fine. You just made my day!!!.

one more thing though, how can i modify the same script to get the samaccountname, emailaddress attribute of managers.

Thanks again!!
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

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 P S

ASKER

Thanks again. Beautiful Script!!!
Question answered.

A D,
please read the following article on how to close your questions properly, once you have your answer:
How do I accept a comment as my solution?
http://support.experts-exchange.com/customer/portal/articles/608621