Get the username of a person logged onto a computer remotely using PowerShell and WMI


So recently I was out visiting a customer who had issues with someone hammering their internet.  We enabled netflow on their Cisco router to do a show top-talkers.  Once we got an IP address we were able to find the machine, but not who.  So I quickly entered the following into PowerShell and got the person we were after (change COMPUTERNAME to the target machine name).

Get-WmiObject Win32_ComputerSystem -ComputerName "COMPUTERNAME" |
Select-Object -ExpandProperty UserName

You will need to have admin rights on the target machine for the above to work.

Another way you can do it is to use wmic to achieve the same result, enter the below into a command prompt window, changing COMPUTERNAME to the target machine;

wmic.exe /node:COMPUTERNAME computersystem get username

Hope that helps someone out.


3 responses to “Get the username of a person logged onto a computer remotely using PowerShell and WMI”

  1. John AG Avatar

    Hi John,

    Great post, actually very handy command. I usually use SCCM, but this can be a little time consuming.

    Simple powershell saves so much time.

  2. John AG Avatar

    Hi John,

    Great post, actually very handy command. I usually use SCCM, but this can be a little time consuming.

    Simple powershell saves so much time.

  3. boB Avatar
    boB

    This is the same thing I’m using to determine if a machine $m is available for maintenance:
    $User = (Get-WmiObject -ComputerName $m.Name -Class Win32_ComputerSystem 2>$null) | Select UserName

    But what I’m finding is this shows me the user logged in LOCALLY, it does not show a user using RDP. Any idea how to identify a remote user??

    Thanks!!

Leave a Reply

More Posts

Checking the performance of your Windows Server 2012 Hyper-V Server with Performance Monitor and PAL

Windows Server 2012 brings some great improvements to Virtualization.  We’re currently running it in production and it works wonders, especially with the new Hyper-V Replica feature which is great and free way of implementing DR.  So now you’ve got that cluster running, how can we tell if it is performing well.   I recently stumbled upon PAL […]

Admin SVC Error when trying to install SharePoint solutions (WSP) and how to fix it

Short and sweet post about deploying SharePoint solutions.  You usually do this by invoking Install-SpSolution under the SharePoint PowerShell, but sometimes you’ll get the following error: Install-SPSolution: Admin SVC must be running in order to create deployment timer job All you need to do is to go to the Services section in Control Panel\System and Security\Administrative Tools […]

Generate Mailbox Size and Usage Report using PowerShell for Exchange 2010 / 2013

So I recently wanted to create a report to show us who was using up the most space on our mailbox servers, previous administrators had either done away for limits for mailboxes or had set them to be very very generous and our users weren’t really the ones to either keep their mailbox tidy or […]