Cyber Security

List all logged on Users with quser.exe and PowerShell

In this short article I will show how to list all logged on local users with the quser.exe tool. Quser displays information about logged on users on the local computer and on a Remote Desktop Session Host server.

PowerShell Code

Enter the code below to determine all logged on users. Multiple users, if any, will be separated by comma.

$users = quser.exe | Select-Object -Skip 1
$unames = @()
foreach ($u in $users) {
    $uname = ($u.trim() -replace '\s+',' ' -replace '>','' -split '\s')[0]
    $unames += New-Object psobject -Property ([ordered]@{
                    'Logged in Users' = [string]$uname
    })
}
Write-Output $unames

The code leads to the following output.

5 replies »

  1. Yes I’ve been using quser a long time to seek out disconnected sessions and their session numbers so that I can reset them on servers.
    Using quser /server: you can find the sessions of users logged on but disconnected then use reset session # /server: to reset those sessions. This is/has been helpful on many occasions. Maybe you can add the above into your ps example. 😊.

    Joost van Haaren
    joost@jvhconsulting.netjoost@jvhconsulting.net
    http://www.jvhconsulting.nethttp://www.jvhconsulting.net/

    Liked by 1 person

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.