It (csv file) should be formatted as follows:

computername
server1
server2
server3

'Computername' is the column name. This can be derived from the code snippet as the Foreach-Object refers to the ComputerName property.

Answer from ravikanth on Stack Overflow
🌐
Microsoft Learn
learn.microsoft.com › en-us › windows-server › administration › windows-commands › query-user
query user | Microsoft Learn
November 1, 2024 - Reference article for the query user command, which displays information about user sessions on a Remote Desktop Session Host server.
Top answer
1 of 3
1

It (csv file) should be formatted as follows:

computername
server1
server2
server3

'Computername' is the column name. This can be derived from the code snippet as the Foreach-Object refers to the ComputerName property.

2 of 3
0

Try this

function Get-MyLoggedOnUsers
{
  param([Array]$Computer)
  Get-WmiObject Win32_LoggedOnUser -ComputerName $Computer |
  Select __SERVER, Antecedent -Unique |
  %{"{0} : {1}\{2}" -f $_.__SERVER, $_.Antecedent.ToString().Split('"')[1],       $_.Antecedent.ToString().Split('"')[3]}
}

$Computers = gc C:\Temp\Computers.txt

Get-MyLoggedOnUsers $Computers

-or-

I found this one and modified it to my needs

<#
.Synopsis
Queries a computer to check for interactive sessions

.DESCRIPTION
This script takes the output from the quser program and parses this to PowerShell objects

.NOTES   
Name: Get-LoggedOnUser
Author: Jaap Brasser
Version: 1.1
DateUpdated: 2013-06-26

.LINK
http://www.jaapbrasser.com

.PARAMETER ComputerName
The string or array of string for which a query will be executed

.EXAMPLE
.\Get-LoggedOnUser.ps1 -ComputerName server01,server02

Description:
Will display the session information on server01 and server02

.EXAMPLE
'server01','server02' | .\Get-LoggedOnUser.ps1

Description:
Will display the session information on server01 and server02
#>
param(
[CmdletBinding()] 
[Parameter(ValueFromPipeline=$true,
           ValueFromPipelineByPropertyName=$true)]
[array[]]$ComputerName = (gc C:\Temp\TSRA.txt)
)

process {
foreach ($Computer in $ComputerName) {
    quser /server:$Computer | Select-Object -Skip 1 | ForEach-Object {
        $CurrentLine = $_.Trim() -Replace '\s+',' ' -Split '\s'
        $HashProps = @{
            UserName = $CurrentLine[0]
            ComputerName = $Computer
        }

        # If session is disconnected different fields will be selected
        if ($CurrentLine[2] -eq 'Disc') {
                $HashProps.SessionName = $null
                $HashProps.Id = $CurrentLine[1]
                $HashProps.State = $CurrentLine[2]
                $HashProps.IdleTime = $CurrentLine[3]
                $HashProps.LogonTime = $CurrentLine[4..6] -join ' '
        } else {
                $HashProps.SessionName = $CurrentLine[1]
                $HashProps.Id = $CurrentLine[2]
                $HashProps.State = $CurrentLine[3]
                $HashProps.IdleTime = $CurrentLine[4]
                $HashProps.LogonTime = $CurrentLine[5..7] -join ' '
        }

        New-Object -TypeName PSCustomObject -Property $HashProps |
        Select-Object -Property UserName,ComputerName,SessionName,Id,State,IdleTime,LogonTime
    } | Out-GridView -Title "Users Logged in $Computer"

   }
}
🌐
Reddit
reddit.com › r/powershell › list of computers - need to find which user is logged in
r/PowerShell on Reddit: List of computers - Need to find which user is logged in
January 13, 2023 -

Hi

I have a list of computer names and need to find the users who are using these computers.

How to fetch these users details via powershell?

Thanks

🌐
Microsoft
devblogs.microsoft.com › dev blogs › scripting blog [archived] › hey, scripting guy! how can i list all user profiles on a remote computer?
Hey, Scripting Guy! How Can I List All User Profiles on a Remote Computer? - Scripting Blog [archived]
December 1, 2009 - I can confirm that the WMI class Win32_UserProfile does not exist on Windows XP. To use the Win32_UserProfile WMI class to list the profiles on a remote computer, use the Get-WmiObject WMI cmdlet.
🌐
AirDroid
airdroid.com › home › remote support › how to see who is logged into a remote computer? [2025]
How to See Who Is Logged into a Remote Computer? [2025]
April 3, 2025 - If you have this suite installed on your computer, you can use the "PsLoggedOn" command [ PsLoggedOn \\RemoteComputerName ] through PowerShell or Command Prompt. Here's how: ... Step 2: Once the screen appears, paste the following command.
🌐
Reddit
reddit.com › r/powershell › how to get a list of users connected via remote desktop sessions (terminal services) on a remote computer.
r/PowerShell on Reddit: How to get a list of users connected via remote desktop sessions (terminal services) on a remote computer.
March 6, 2020 -

Hi guys,

I have a bit of an odd request here. I have a requirement to pull a list of currently signed-in Remote Desktop (both active and disconnected) users on a remote system via powershell.

If at all possible, I would prefer to avoid using query user (quser) or query session (qwinsta) simply due to the length of time it can take to retrieve the data using those commands, as well as in the environment that I'm in, they only appear to work about 15-20% of the time.

I would also prefer to avoid installing any additional powershell modules if I can, since some of the networks I will be running this script on wont have any connection to the internet to pull the modules from.

I have looked at pulling a list of all users on the system who have an 'Explorer.exe' process running, but that doesn't differentiate between locally signed in users and remote users.

I'm running into a bit of a wall here, I cant seem to find anything online that would fit the bill.

🌐
DevOps on Windows
devopsonwindows.com › home › articles › 3 ways to remotely view who is logged on
3 Ways to Remotely View Who Is Logged On
September 2, 2014 - Last but not least, there’s the built-in Windows command, “query”, located at %SystemRoot%\system32\query.exe. Just open a command prompt and execute: query user /server:server-a
Find elsewhere
🌐
Microsoft Learn
social.technet.microsoft.com › Forums › lync › en-US › 962762e2-4553-4f33-a3c8-d9eb8290da65 › remote-desktop-show-which-user-connected
Remote desktop show which user connected | Microsoft Learn
January 17, 2023 - Played around with som local interactive policies but no success. ... Install remote desktop services manager and then you can use it to connect to the remote machine and view all users who are logged in. It works for servers.
🌐
MSPoweruser
mspoweruser.com › home › windows › see who is logged into a remote computer: 6 best ways
See Who Is Logged Into a Remote Computer: 6 Best Ways
October 26, 2025 - Another way to identify the user of a remote computer is to use the Task Manager utility. First, you need to open Task Manager by pressing Ctrl + Alt + Delete or Ctrl + Shift + Esc.
🌐
Lepide
lepide.com › how-to › list-all-user-accounts-on-a-windows-system-using-powershell.html
How to List All User Accounts on a Windows System Using PowerShell
November 20, 2024 - Get-LocalUser is limited to listing accounts on the system where the command is run. But Get-WmiObject queries local users on remote systems using Windows Management Instrumentation (WMI). Get-WmiObject -ComputerName workstation1 -Class Win32_UserAccount -Filter "LocalAccount=True"
🌐
AnyViewer
anyviewer.com › how-to articles › how to check users logged in remote desktop [full guide]
How to Check Users Logged in Remote Desktop [Full Guide]
December 13, 2024 - To detect successful login attempts, ... through the search feature on the taskbar. Step 2. Navigate through the tree structure on the left panel to "Windows Logs" > "Security"....
🌐
Host IT Smart
hostitsmart.com › manage › knowledgebase › 394 › How-to-Check-Users-Logged-in-Remote-Desktop.html
How to Check Users Logged in Remote Desktop?
June 30, 2025 - ➔ Once you enter the Task Manager, click the ‘Users’ tab. ➔ Here, you will see a list of users currently logged into local and remote desktops. Also Read: How to Create a User in RDP for Windows Server? ➔ Type ‘Event Viewer’ in the search bar of your Windows computer.
🌐
Bradley Schacht
bradleyschacht.com › find-users-logged-into-remote-computer
Find Users Logged Into Remote Computer
May 24, 2024 - Just fire up the command prompt or PowerShell and run this: query session /server:"" query session /server:"KERBEROS-SP" As we see in the screenshot there is one user logged into this computer, the Administrator account.
🌐
Spiceworks
community.spiceworks.com › programming & development
who is logged on remote pc from which computer - Programming & Development - Spiceworks Community
September 24, 2018 - I have a domain admin account. I want to find out who is logged in to PC1 from which computer/ip ? currently I can only query which username is logged on PC1 but non of command showed from which computer this user is logged in to PC1. So far I have used pstools \\PC1 query user (this only shows username , not computer name from which the user is loggedin) WMIC /NODE: "PC1" COMPUTERSYSTEM GET USERNAME
🌐
Next of Windows
nextofwindows.com › home › how to get the list of user profiles on local and remote computer
How To Get the List of User Profiles on Local and Remote Computer - NEXTOFWINDOWS.COM
April 2, 2020 - There is a better way that can get a list of user profiles on both local and remote computers, using the Get-WmiObject cmdlet with Win32_UserProfile, such as below to get the list of user profiles on the local computer.
🌐
The Sysadmin Channel
thesysadminchannel.com › home › get logged in users using powershell
Get Logged In Users Using Powershell - the Sysadmin Channel
February 9, 2022 - A quick and easy way to get logged in users to any server or computer. It's a command to check users logged in windows remotely.
🌐
ManageEngine
manageengine.com › adaudit plus › how to › how to view logged-on users in windows using cmd, powershell, and task manager
How to view logged-on users in Windows using CMD, PowerShell & Task Manager
Task Manager: Open Task Manager > Users tab to see logged-in users and their status (GUI required). These methods work across Windows Server 2008-2022 and Windows 10/11, providing both console and remote session visibility.