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: Rakesh
Author Info:

Rakesh is a seasoned developer with over 10 years of experience in web and app development, and a deep knowledge of operating systems. Author of insightful How-To articles for Code2care.

Follow him on: X

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