locked
Get logged in user of RDP machine RRS feed

  • Question

  • I have looked long and hard for a way of getting the logged in user for a machine that they have remoted into with PowerShell.

    I have a bench full of test PC's and apart from certain software versions, which I can get, I would like to be able to find out who is using which PC.

    If a user is logged physically into a machine there is no problem using below.

    $LoggedInUser = Get-WmiObject Win32_ComputerSystem –ComputerName $Computer | select username

    Is there a way to get a remote lodged in user?

    And if Ed gets this one, I do remember attending a VBS course he held here in Brisbane Australia. Many years ago and a great course.

    Thanks

    Nick

    Monday, June 12, 2017 11:19 PM

Answers

  • For most systems this works:

    Invoke-command {(Query user) -replace '\s{2,}', ','|ConvertFrom-Csv} -Computer remotepc


    \_(ツ)_/

    • Marked as answer by Nick Bowden Wednesday, June 14, 2017 2:49 AM
    Tuesday, June 13, 2017 1:50 AM

All replies

  • query user /server:remotesystem

    \_(ツ)_/


    • Edited by jrv Monday, June 12, 2017 11:37 PM
    Monday, June 12, 2017 11:36 PM
  • Care for objects?

     (Query user /SERVER:rdsserver) -replace '\s{2,}', ','|ConvertFrom-Csv


    \_(ツ)_/

    Monday, June 12, 2017 11:48 PM
  • Thanks jrv

    Tried this (Query user /SERVER:PC526510) -replace '\s{2,}', ','|ConvertFrom-Csv

    and got this.

     Query : Error 0x00000005 enumerating sessionnames

    At line:1 char:2
    + (Query user /SERVER:PC526510) -replace '\s{2,}', ','|ConvertFrom-Csv
    +  ~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (Error 0x0000000...ng sessionnames:String) [], RemoteException
        + FullyQualifiedErrorId : NativeCommandError

    Error [5]:Access is denied.

    Tried this (Query user /PC526510) -replace '\s{2,}', ','|ConvertFrom-Csv

    Got this

    Query : Invalid parameter(s)
    At line:1 char:2
    + (Query user /PC526510) -replace '\s{2,}', ','|ConvertFrom-Csv
    +  ~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (Invalid parameter(s):String) [], RemoteException
        + FullyQualifiedErrorId : NativeCommandError

    Tuesday, June 13, 2017 1:44 AM
  • If management ports are not open to you it will fail.

    Also it only works against full RDS in licensed mode when executed remotely.


    \_(ツ)_/


    • Edited by jrv Tuesday, June 13, 2017 1:47 AM
    Tuesday, June 13, 2017 1:45 AM
  • For most systems this works:

    Invoke-command {(Query user) -replace '\s{2,}', ','|ConvertFrom-Csv} -Computer remotepc


    \_(ツ)_/

    • Marked as answer by Nick Bowden Wednesday, June 14, 2017 2:49 AM
    Tuesday, June 13, 2017 1:50 AM
  • jrv

    Thanks for that. This threw out an error, but due to the error, I have found out that the security on our network is blocking it. 

    Regards Nick

    Wednesday, June 14, 2017 2:54 AM