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

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

  • For SharePoint Admins
    1 Posts | Last post October 23, 2015
    • GREAT SCRIPT! Not a question, but if you are working with SharePoint here is a slightly modified version to check all Farm members.
      #Add SharePoint PSSnapin if it not already loaded:
      $ver = $host | select version 
      if ($ver.Version.Major -gt 1) {$Host.Runspace.ThreadOptions = "ReuseThread"} 
      if((Get-PSSnapin -Name microsoft.sharepoint.powershell -EA "SilentlyContinue") -eq $null){
      	Add-PsSnapin microsoft.sharepoint.powershell;
      } Clear-Host
      function Get-LoggedOnUser { 
      #Requires -Version 2.0             
      Param (                        
      )#End Param 
      Begin {             
      	Write-Host "`n Checking Users . . . " 
      	$i = 0             
      Process { 
          $ComputerName | Foreach-object { 
          $Computer = $_ 
          try { 
      		$processinfo = @(Get-WmiObject -class win32_process -ComputerName $Computer -EA "Stop") 
      		if ($processinfo){     
      			$processinfo | Foreach-Object {$_.GetOwner().User} |  
      			Where-Object {$_ -ne "NETWORK SERVICE" -and $_ -ne "LOCAL SERVICE" -and $_ -ne "SYSTEM"} | 
      			Sort-Object -Unique | 
      			ForEach-Object { New-Object psobject -Property @{Computer=$Computer;LoggedOn=$_} } |  
      			Select-Object Computer,LoggedOn 
      	} catch { 
      		"Cannot find any processes running on $computer" | Out-Host 
      	} }#Forech-object(Comptuters)        
      End {}#End 
      Get-SPServer | ?{$_.Role -eq "Application"} | ForEach-Object {
      	Get-LoggedOnUser $_.Name
  • Multiple computers applications
    2 Posts | Last post May 12, 2015
    • Is it possible to get list of installed application under one OU in active Directory.  I have 30 computers in One OU in Active Directory.  Needs to get list of all applications installed on those machines.
    • Anything is possible, however you will do the task in two different scripts.
      1) read the computer account names from the OU
      2) read the application lists from the servers
      There are already scripts that do both of these tasks if you search.
  • How do I
    5 Posts | Last post January 23, 2015
    • 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.
    • On the "create a profile" Suggestion, I get an error:
      PS C:\scripts> New-Item $PROFILE.CurrentUserAllHosts -ItemType File
      New-Item : Could not find a part of the path 'C:\Users\administrator\Documents\WindowsPowerShell\profile.ps1'.
      At line:1 char:9
      + New-Item <<<<  $PROFILE.CurrentUserAllHosts -ItemType File
          + CategoryInfo          : WriteError: (C:\Users\admini...ell\profile.ps1:String) [New-Item], DirectoryNotFoundException
          + FullyQualifiedErrorId : NewItemIOError,Microsoft.PowerShell.Commands.NewItemCommand
      It appears the first step should be "md WindowsPowerShell" (make a powershell directory under the folder for the profile you are trying to create).
    • FOUND IT! Okay, your function needs to be "loaded AS a function, and run as a function." It cannot be run as a standalone script. That was not made very clear. Maybe it should be obvious, but I'm just telling you that it is not clear that that is what is needed (maybe 'powershell [experts]' would already know that, but not 'normal mortal human beings'). That probably should have been THE first thing you mentioned. This is a very nice script offering! Thank you!
    • Well glad you got it worked out :)
  • Okay, I get "empty" output - nothing, nada, zilch
    2 Posts | Last post January 21, 2015
    • When I run your function, I get no output, not even the error about "no processes running." Also, on your note to another user you gave the wrong syntax, you said to use "Get-LoggedOnUser -ComputerName ServerName" - but you don't have a "-ComputerName" qualifier. Should be "Get-LoggedOnUser ServerName".
      Either way, from my "domain admin" PS prompt (so you know there's no permission issue), Get-WmiObject -class win32_process -ComputerName "RemoteServer" works perfectly! And yet, when I execute "Get-LoggedOnUser RemoteServer" - I get no errors, no messages, NO output whatsoever, from the exact same elevated (domain admin) session. What gives? I am on Server 2008 R2, with PS 2.0, full privs. Now, I did NOT "cut and paste" your script - I grabbed it via the "Download" button, in case there's a difference - maybe that's the issue? Maybe something wasn't corrected in the downloadable version? Haven't yet tested the 'cut-n-paste' version that is listed on the page here. Thanks.
    • I did some stub-testing: I placed a "Write-Host" just above the word 'function,' and that produces output just fine; but then, it's like, no matter what you enter as a parameter, it 'falls through' (bypasses) the entire function, and gives no output.
      So, what am I doing wrong? Basically, from within PS, I do: 
      .\Get-LoggedOnUser.ps1 RemoteServerName
  • just great
    1 Posts | Last post September 12, 2014
    • 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?
  • 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.
1 - 10 of 15 Items