Finding Logged On Users

by Jul 23, 2015

In a previous tip we explained how you find the physically logged on user. In this tip you will see how you can list the current logon sessions, reporting all users who are currently logged on to a system. This includes users that are connected via RDP and other means:

#requires -Version 1
function Get-LoggedOnUserSession

    Get-WmiObject -Class Win32_LogonSession @PSBoundParameters |
    ForEach-Object {
        $_.GetRelated('Win32_UserAccount') |
        Select-Object -ExpandProperty Caption 
    } |
    Sort-Object -Unique

When you run Get-LoggedOnUserSession, you get back all users that are currently connected to your machine. Specify the -ComputerName and optionally the -Credential (domain\username) parameters to access remote machines.

Twitter This Tip! ReTweet this Tip!