Link to home
Start Free TrialLog in
Avatar of karlpearson
karlpearsonFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Get real name from ad account logon name

Hi,

Hope someone can help me please. I am looking for a powershell script that will take a txt file containg AD usernames and output next to the usernames the real names from the AD accounts of the user's in question. e.g.

Username         Real name
usera                John Smith
userb                Davey Jones

Is this possible in powershell? or does this need to be done in vbs.

Hope someone can help out.

Regards,

Karl.
Avatar of Michael
Michael

ASKER CERTIFIED SOLUTION
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

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
This solution uses Quest's AD snapin and outputs the result into Users2.TXT file. Customize the paths in lines 1 and 6.
$users = Get-Content c:\ee\users.txt

Add-PSSnapin Quest.ActiveRoles.ADManagement -ErrorAction silentlycontinue
$users | ForEach-Object {
    Get-QADUser -SamAccountName $_ | Select-Object @{n="Username";e={$_.samaccountname}}, @{n="Real name"; e={$_.displayname}}
} | convertto-Csv -NoTypeInformation -Delimiter "`t" | %{$_ -replace '"',""} | Set-Content -Path C:\ee\users2.txt -Encoding unicode

Open in new window

Avatar of karlpearson

ASKER

Great stuff thank you