'How to display all users on the server/computer with a Windows batch script?

I am new to batch scripting and learning as I go along. I am basically trying to display all the users that may be on that specific server or computer by doing:

echo %USERNAME% 

Is this enough to display all the local users or will it just display one local user?



Solution 1:[1]

Do you have the Home version of Windows? If so, then your options are more limited - see here. You should still be able to use PowerShell, or download another option. But in other versions of Windows you can use QUSER.

To check a remote computer with QUSER:

QUERY USER /SERVER:ComputerName

Return something such as this:

 USERNAME              SESSIONNAME        ID  STATE   IDLE TIME  LOGON TIME
 RemoteUserID          console             1  Active      none   4/29/2022 6:14 AM

To see options, type:

QUSER /?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Darin