logged on users in array or object (powershell, command line) RRS feed

  • Question

  • I have few Windows Server 2012 R2 with RDS installed and I need to have function which returns array or object with users and their session IDs on specified server. I need to run this function with non-admin permissions. On the session hosts I ran this command:

    wmic /namespace:\\root\CIMV2\TerminalServices PATH Win32_TSPermissionsSetting WHERE (TerminalName ="RDP-Tcp") CALL AddAccount "domain\group",2 the users have elevated permissions and now they can use RDS shadowing through command line. The ID which I need is the session ID which I can get for example from command "quser". The best solution will be if I will have function which returns array (with logged on users on the specific server) like this (or something similar, maybe object):

        LOGIN    ID
        user1 -> 3
        user2 -> 4
        user3 -> 5
    I really appreciate any help you can provide... Thank you.....
    • Edited by d3vl1n Tuesday, December 10, 2013 8:52 PM
    Tuesday, December 10, 2013 8:49 PM


  • Very good.  Make everybody and administrator. 

    Why no just give them shadow capability.

    Just parse quser into an array.  This will get you started.

    $arr=guser|%{$_.Split(' ')}


    • Marked as answer by d3vl1n Thursday, January 2, 2014 1:48 PM
    Tuesday, December 10, 2013 9:06 PM