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

Specify ClickView Server IP settings via the Registry using Group Policy with an ADMX Template

So I was recently going through our Group Policy and found that we were applying a reg file to specify the Server IP for our ClickView Players.  I don’t really like this approach anymore and tend to try and have everything nice and neat so I set about creating a ADM file to store the […]

Moving the SQL Server tempdb file location after SQL Server is installed

Working with one of my education customers I recently had to perform some maintenance on their SQL Database server as they were running low on disk space AND had a free unused virtual disk where we could throw their tempdb onto (it was meant to go here but they didn’t place it there during installation). […]

Useful Debug commands for ArubaOS (AOS) Switches

I was recently out at a site working through an 802.1x wired implementation, their site runs all Aruba Networking gear running older style ArubaOS (or AOS) which is basically the ProCurve/ProVision with a mix of 2930f, 3810m switches and 5406zl chassis. The hard work of certificates has already been done sine we earlier did a […]