• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 893
  • Last Modified:

Get real name from ad account logon name


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.


1 Solution
MichaelSystems EngineerCommented:
Chris DentPowerShell DeveloperCommented:
PowerShell can do it, there's a variety of different ways.

Quest CmdLets:
Get-Content YourFile.txt | Get-QADUser | Select-Object Name, SamAccountName

Open in new window

Exchange CmdLets:
Get-Content YourFile.txt | Get-Mailbox | Select-Object Name, SamAccountName

Open in new window

AD CmdLets:
Get-Content YourFile.txt | Get-ADUser | Select-Object Name, SamAccountName

Open in new window

Native (no CmdLets - PowerShell 2):
Get-Content YourFile.txt | ForEach-Object {
} | Select-Object @{n='Name';e={ $_.Properties["name"][0] }}, @{n='SamAccountName';e={ $_.Properties["samaccountname"][0] }}

Open in new window

In all cases you can write to a file by adding a  pipe into "Export-Csv" on the end.


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

karlpearsonAuthor Commented:
Great stuff thank you

Featured Post

Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now