PowerShell Get Currently Logged In User on Mac

If you are using PowerShell prompt on Mac Terminal and want to know who is currently logged in, you can make use of the below commands,


Option 1: who command

PS /> who

code2care        console      Sep 14 10:58 
code2care        ttys000      Sep 14 10:58 
code2care        ttys001      Sep 14 10:58 

Option 2: whoami command

PS /> whoami

code2care

Option 3: $env:USER command

PS /> $env:USER

code2care

Note: As PowerShell is not native to macOS, the command that works on PowerShell for Windows may not work and you will get an error.

PS /> (Get-WmiObject -Class Win32_ComputerSystem).UserName

Get-WmiObject: The term 'Get-WmiObject' is not recognized as a name of a cmdlet, 
function, script file, or executable program.

Check the spelling of the name, or if a path was included, 
verify that the path is correct and try again.
PowerShell - Know Current Logged In User details on Mac

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!