Windows – How to list local users on a Windows Server 2003 including Description and Full Name from command line

windows-server-2003

I need a full list of local users defined on a Windows Server 2003. It is not a part of an AD domain. I have found typing "NET USER" on the command line lists all users, but it does not include the Description or Full Name field, which I need. I can't find any command line option for it either.

It doesn't HAVE to be command line. The clue is I need to copy-paste the data into a processable format. The Computer Manager console is not a fan of copy pasting.

Best Answer

Copy this into a .JS file.

var objWMIService = GetObject("winmgmts:\\\\.\\root\\cimv2");

var listLocalUsers = objWMIService.ExecQuery("SELECT * from Win32_UserAccount Where LocalAccount = True");

for(var enumLocalUser = new Enumerator(listLocalUsers); !enumLocalUser.atEnd(); enumLocalUser.moveNext()){
    var localUser = enumLocalUser.item();
    WScript.Echo("Short Name: " + localUser.Name);
    WScript.Echo("Full Name: " + localUser.FullName);
    WScript.Echo("Description: " + localUser.Description);
    WScript.Echo("\n");
}

VB example: On Error Resume Next Set objWMIService = GetObject("winmgmts:\.\root\cimv2") Set listLocalUsers = objWMIService.ExecQuery("Select * from Win32_UserAccount Where LocalAccount = True")

For Each localUser in listLocalUsers 
    Wscript.Echo "Short Name: " & localUser.Name 
    Wscript.Echo "Full Name: " & localUser.FullName 
    Wscript.Echo "Description: " & localUser.Description 
    Wscript.Echo "\n"
Next 

Then run it using cscript myGetLocalUsers.js or cscript myGetLocalUsers.vb at the command prompt.

Edit:

I haven't tested it so let me know if you get any errors.

Related Question