Find Physically Logged On User

by Jul 22, 2015

There can always be only one physically logged on user on a machine. The physically logged on user is the one sitting right at the machine.

Here is a PowerShell function that reports the physically logged on person for a local or remote system. To access a remote system, you would need local Administrator privileges on the remote machine, and make sure your firewalls are configured correctly to let you connect.

#requires -Version 1
function Get-LoggedOnUser

    Get-WmiObject -Class Win32_ComputerSystem @PSBoundParameters |
    Select-Object -ExpandProperty UserName

Once you run Get-LoggedOnUser, you get back the name of the physically logged on user on the local machine. Use the –ComputerName (and optionally –Credential) parameters to access a remote machine.

Twitter This Tip! ReTweet this Tip!