Finding Logged-On User on Remote Machine

by Jan 15, 2014

In a previous tip we used quser.exe to find the currently logged-on user on the local machine. Here is now a function that also allows us to find the currently logged-on user on a remote machine. As an extra benefit, the returned information is appended by a property called "ComputerName", so when you query multiple machines, you will know where the results came from:

function Get-LoggedOnUser
{
  param([String[]]$ComputerName = $env:COMPUTERNAME)

    $ComputerName | ForEach-Object {
      (quser /SERVER:$_) -replace '\s{2,}', ',' | 
        ConvertFrom-CSV |
        Add-Member -MemberType NoteProperty -Name ComputerName -Value $_ -PassThru
  }
} 

And here is a sample call, querying the local computer plus a remote system:

Twitter This Tip! ReTweet this Tip!