Using PowerShell, how can I get the currently logged on domain user's full name (not only its username) without the need of the ActiveDirectory module?
Using PowerShell, how can I get the currently logged on domain user's full name (not only its username) without the need of the ActiveDirectory module?
Returns:
Some other (mostly) obscure properties also available. A few useful ones:
Try:
I like the accepted answer, but just because I wanted to try this out myself:
returns:
or if you wish to not have the header info and just the result:
One liner using Powershell 3.0:
Based on your comment on Craig620's accepted answer,
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.If you've always got .Net 3.5 or higher (which you should with PowerShell v4.0 and higher):
That class provides very easy access to all the common LDAP properties, so you don't need to lookup twice (once with WinNT and again with LDAP) or use
[ADSISearcher]
to do an LDAP search if you want some extended properties that WinNT doesn't implement.You can retrieve a truckload of information using this very simple tool. Check out
Using -match is not a good choice because a $env:USERNAME of "ed" will match "fred" and "edith". Instead use -eq for an exact match and add in the domain if needed. I use a foreach loop at the end to strip off all leading an trailing whitespace as an alternative to "select fullname | ft -HideTableHeaders" which prints a leading and trailing newline.
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.
How about querying the registry instead of AD Like this:
Note: Only tested on Windows 10.
Another Note: this looks for the first logged user in the current session, so for example if you logged out of john.smith and logged in will.smith and run the above you will get the data related to john.smith instead of will.smith.Update: The below script will get the current user's display name regardless of being on a domain joined PC or not or logging in with another account before logging in with the account that you need to get the display name for.