I found it:
[Environment]::UserName
$Env:UserName
There is also:
$Env:UserDomain
$Env:ComputerName
Answer from Thomas Bratt on Stack OverflowTrying to get it current user name display name without using active directories is it possible?
For now I’m Using
$appuser = (get-aduser ($env:username)).name
But I’m trying to find a way without using the ADuser
How to get the user's displayName when using PowerShell 2.0 and the Active Directory module is not present?
How to make my powershell script reference the current user account who is running it?
Get current user on local machine using Powershell - Stack Overflow
Get the "friendly" name for logged-in User (AD)
Videos
$dom = $env:userdomain
$usr = $env:username
([adsi]"WinNT://$dom/$usr,user").fullname
Returns:
John Doe
Some other (mostly) obscure properties also available. A few useful ones:
- Homedrive UNC
- Homedrive Letter
- Description
- Login script
Try:
[adsi]"WinNT://
usr,user" | select *
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
Part of my script involves making yourself a site admin for OneDrive data (set-spouser), then adding the manager, then removing yourself. Since I've always been the only one using this script, I've hardcoded my username into the script. However, other people will be using this script.
When it comes to connecting to exchange online or other admin portals, it's easy to do. You just leave the -userprincipalname field empty, and you get a popup box asking to enter your username, then your password. How do you "leave empty" which account you want to make a site admin for OneDrive data?
I hate that I don't know the terminology for what I'm asking -- which is also probably why I can't find it on Google. When logged into my PC at work, using Active Directory, I can see my full name on my personal folder when I click on the Start Menu. But when I run something like, whoami, I just see my login (something like my first initial and last name.) How I can I get the prior?