Find the logged on users on a remote system/s

DescriptionThis script should be useful for Helpdesk or other IT Admins to query remote machines to see who is logged on.This could also be useful for Remote Desktop Services or Citrix Admins* Note this scripts also returns non system accounts that are running services. Use like:

8,388 times
Add to favorites
E-mail Twitter Digg Facebook
Sign in to ask a question

  • just great
    1 Posts | Last post Fri 4:53 PM
    • Thank you very much for this nice script.
  • Only works for some remotes
    2 Posts | Last post February 11, 2014
    • Hi, I tested out your code and it works fine but for some computers, I can't tell who's logged on remotely.  Once I execute the "get-loggedonuser" command it will say "Cannot find any processes running" on a certain remote when I know a user is logged on remotely.  I'd appreciate some help in this matter.
    • You are querying a WMI NameSpace/Class for this information.
      You can test the raw cmdlets: 
      Get-wmiobject -namespace root\cimv2 -class win32_process -CN WS123
      By default the class requires you to have local admin rights to query.
      If you want you can use some other credentials:
      $cred = get-credential domain\user
      Then add the following to the get-wmiobject query:
       -credential $cred
      Let me know how you go.
      This used DCOM/RPC to query which requires a large range of network ports to connect, if you can use compmgmt.msc and connect to the remote machine, then you should have permission to connect with Get-wmiobject.
  • Big thanks Ben for a great tool.
    2 Posts | Last post November 27, 2013
    • I am just now beginning to understand Powershell. So see good examples of reall world usage really helps. I used both the loggedonuser and test-online scripts without issues. I can already see where this will be very helpful. I sure appreciate your sharing and the hellpful answers to other peoples questions were great too.
    • Thanks for the feedback Johnny, I really appreciate it  :)
      Glad you find the tools useful.
      Hopefully they can inspire you to also also create tools for tasks that you commonly perform.
  • Identify Idle Users
    2 Posts | Last post October 17, 2013
    • Hi first of all, thank you for that nice script!
      I currently using "query user /server" for those kind of jobs and i am looking for a way to do that via PS. So I found this nice one. Do you mean it is possible to check users, so i can see which of those are in status active or disconnected like in "user query"?
    • I prefer to use this module for those kinds of tasks, this has some very useful cmdlets:
      You gain the advantage of the results being PowerShell objects which makes customizing the output via the pipeline easier to achieve than .exe commands.
  • output to cvs
    2 Posts | Last post August 28, 2013
    • how to output results to csv not screen?
      something like?  where to include in file to output to csv?
      | Export-CSV C:\output.csv 
    • Yes that will work, exactly.
      Did you try it?
  • How do I
    2 Posts | Last post April 16, 2013
    • Get your script to permanently be loaded into PS? I have to load it every time I open powershell.
    • Hi Todd.
      The secret it to create a profile and then load it in the profile.
      New-Item $PROFILE.CurrentUserAllHosts -ItemType File
      Then open the file:
      notepad $PROFILE.CurrentUserAllHosts
      Then add the dot source in that script to load the function.
      . c:\fullpath\Get-LoggedOnUser.ps1
      Then save and close the file, the next time you open powershell that script will run and the function will be available for you to call.
  • The same - no output from the script
    2 Posts | Last post April 16, 2013
    • Hi!!
      When I running this script on Windows 8 Pro against two remote Windows 2003 servers, there is no aoutput at all from the script...I've followed your recomendation  (running powershell as admin, used . . c:\fullpath\Get-LoggedOnUser.ps1) but it seem that function didn't loaded at all... What do you think?
    • just use the single dot, then space to wherever you downloaded the script to.
      . c:\fullpath\Get-LoggedOnUser.ps1
      After that it should be in memory.
  • What does this error mean
    2 Posts | Last post January 20, 2013
    • Hi I used this script along with TEST-ONLINE script but for most of the machines i see the below error. can you please help.
      Checking Users . . .
      VERBOSE: Online : cg000164578
      Cannot find any processes running on cg000164578
      VERBOSE: Online : fh00024990
      Cannot find any processes running on fh00024990\
      I checked both the machine and OS was Windows XP Professional-sp2
      Overall its a excellent script!!!
    • Hi iis4313,
      It seems like either you do not have permission to run the wmi query against the remote machine OR there is a problem with wmi on the remote machine.
      The actual query that is failing is:
      Get-WmiObject -class win32_process -ComputerName "cg000164578"
      So if you run that you will get your error.
      In General you need to be a local administrator on a machine to run the query.
  • No Output
    3 Posts | Last post November 28, 2012
    • I am getting no output from this script at all.  I have no clue what I am doing wrong.
    • Hi Dave, try this.
      step 1) Download the file and save it to a known location.
      step 2) Open the powershell console (running as Administrator/elevated)
      step 3) dot source the file/function into memory:
      . c:\fullpath\Get-LoggedOnUsers.ps1
      That is dot, then a space, then the full path to the file, then press enter.
      step 4) see if the function is loaded: Get-item function:\Get-LoggedOnUsers
      step 5) call the function via: Get-LoggedOnUsers -computername server123
    • sorry it should be Get-LoggedOnUser not Get-LoggedOnUsers notice the singular.
  • Is there any way to change the timeout ?
    5 Posts | Last post August 18, 2012
    • I'm using this script with "get-content xxxx.txt" and it works fine...
      The only thing is that I have around 2k pc to parse...
      so when they are offline it takes a while before I get the "Cannot find processes..."
      I was wondering if there is anyway to put a timeout to search in xxx milliseconds ?
      Thanks for your help !
    • Sure thing, I wrote this function called Test-Online.
      If you install that you can use it as part of the pipeline along the way.
      Download here:
      Then you can go: 
      Import-Csv -Path C:\ps\computers.csv | Test-Online | Get-LoggedOnUser
      get-content -Path C:\ps\computers.csv | Test-Online | Get-LoggedOnUser
      LOVE that pipeline. Let me know how you go?
    • WONDERFULL !!! thanks alot :)
    • Help again :)
      I'm trying to pipe "Get-ADComputer -Filter * -Property * | Format-Table Name" this way :
      $CptList = Get-ADComputer -Filter * -Property * | Format-Table Name -autosize
      $Cptlist | Out-String | Test-Online | Get-LoggedOnUser
      But I get that 0 Computers online... (I think it doesn't like the variable format... can you help me out ?
    • Wen you use Format-Table you kill the object and it can never be consumed anywhere else. so saving to a variable is not very useful, since any format command it really only useful to view the output on the screen.
      So try to use Select-Object instead of Format-Table (the results on the screen look similar, however under the covers Select-Object is far more useful).
      So anywhere there are a couple of ways to do this:
      1) Use expandproperty to get one property Name into a simple list. 
      $ComputerList = Get-ADComputer -Filter * -Property * | Select-Object -ExpandProperty Name
      Then: $ComputerList | Test-Online | Get-LoggedOnUser
1 - 10 of 12 Items