Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Using Powershell,

how can I get the currently logged on domain user's full name? Not only its username.

Thanks

EDIT: without the need of the activedirectory module!

share|improve this question

5 Answers 5

up vote 10 down vote accepted
PS C:\temp> $dom = $env:userdomain
PS C:\temp> $usr = $env:username
PS C:\temp> ([adsi]"WinNT://$dom/$usr,user").fullname
John Doe

Some other (mostly) obscure props also avail.
A few useful ones: Homedrive UNC, Homedrive Letter, Description, Login script
Try:
[adsi]"WinNT://$dom/$usr,user" | select *
share|improve this answer
2  
Good answer. Of course, this is querying AD... :) –  Massimo Mar 17 at 20:31
1  
Do I need domain admin rights to run this command? Or can the domain user itself can run this command? –  Jonathan Rioux Mar 17 at 21:02
1  
Any domain user can query AD for this kind of information. –  Massimo Mar 20 at 16:43

I like the accepted answer, but just because I wanted to try this out myself:

$user = whoami
Get-WMIObject Win32_UserAccount | where caption -eq $user | select FullName

returns:

FullName
--------
TheCleaner

or if you wish to not have the header info and just the result:

$user = whoami
Get-WMIObject Win32_UserAccount | where caption -eq $user | select FullName | ft -hide
share|improve this answer
    
I read this too quickly, it does query AD. I verbally retract my vote. –  BigHomie Mar 17 at 21:14
2  
But doesn't require the AD PS modules –  squillman Mar 17 at 21:28
3  
@squillman it doesn't, just giving Cleaner a hard time. –  BigHomie Mar 17 at 21:31
    
Gotcha. Sorry, must have been decaffeinated... –  squillman Mar 18 at 14:44

One liner using Powershell 3.0:

gwmi win32_useraccount | where {$_.caption -match $env:USERNAME} | select fullname | ft -HideTableHeaders
share|improve this answer

Based on your comment on Craig620's accepted answer,

Do I need domain admin rights to run this command? Or can the domain user itself can run this command?

It sounds like you're trying to avoid installing powershell modules on user workstations, yes, but also, no, you don't need to be a domain admin to look up your own name in AD. You can look up pretty much any information that appears in the GAL in Outlook, including full name, as a standard user.

You can also look up other people's full names as a standard user in AD (using Get-WmiObject Win32_userAccount, if you want to avoid the AD modules). Service accounts that query AD (well, prior to managed service accounts) are usually standard, unprivileged AD users.

share|improve this answer

If you don't want to use the Active Directory module, you can't; unless you want to go even deeper and perform an actual LDAP query against a domain controller.

Any user information other than the username is stored in Active Directory, and it has to be retrieved there.

share|improve this answer
    
But when I open the start menu, the full name of the user is shown here! I mean, it must be stored somewhere? –  Jonathan Rioux Mar 17 at 20:18
3  
Yes, it's stored somewhere. It's stored in Active Directory. –  Katherine Villyard Mar 17 at 20:26
    
It is probably stored/cached in the registry as well, but I didn't find it easily and gave up. –  mfinni Mar 17 at 21:35
1  
It's true that it's stored in AD but the [ADSI] interface has been around a lot longer than the AD modules, and really isn't all that complicated, like the accepted answer shows. –  Hunter Eidson Mar 20 at 15:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.