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

Moving your SUSDB when it is running under MSDE

During my morning rounds of looking after clients’ servers, running SBS 2008. I noticed one was running out of space.  It had recently been updated to WSUS 3.0 SP2, after doing a quick hard drive space check I found that SUSDB was over five gigabytes in size. Generally this database should be around one gig.  […]

CrowdStrike Next-Gen SIEM and FortiGate Connector

So I’m working on getting all of our external systems connected into the CrowdStrike Next-Gen SIEM as part of our internal Falcon Complete tenancy. Following the documentation in the CrowdStrike portal, getting and installing the Log Collector and setting up the connector were a pretty straightforward affair. I’ve got a Windows VM setup as a […]

Linux VM Performance on Hyper-V

I was recently on a call with a customer who had migrated their VMs to a new Hyper-V host (and away from VMWare) and had a few Ubuntu VMs for hosting their PHP stack of applications. Part of the call we were doing a review of some of the VMs and the customer complained that […]