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

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap