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

 
 
 
 
 
4.8 Star
(25)
32,723 times
Add to favorites
11/14/2014
E-mail Twitter del.icio.us Digg Facebook
  • Disconnected / Locked users
    1 Posts | Last post December 15, 2019
    • Is there any way to make this script return users that are logged on but their session is disconnected / locked?
      
  • how to add WMI-Objects to this scrip
    2 Posts | Last post January 10, 2018
    • Hi Ben, 
      
      Thank you for the great script. I was wondering how to add a few objects to be able to confirm the manufacture serial number, OS version, etc. 
      
      
      thank you,
      vincent 
    • Perhaps take a look at this script.
      
      https://gallery.technet.microsoft.com/scriptcenter/Find-System-Hardware-b68938c8?redir=0
  • Help me
    2 Posts | Last post November 13, 2017
    • Hey
      I started with Powershell last week and i can't get the "Get-LoggedOnUser" to work at all.
      Can someone help with that ? I have tried to google and Youtube it. But nothing works
    • There are detailed instructions below: 
      
      look for . ..
      
      "How do you run the script"
      2 Posts | Last post December 15, 2016
  • does it tell you about remote user as well
    2 Posts | Last post March 17, 2017
    • 
      
      Does your script tells you that User is logged in as Local or Remote. and how do I know how many users are logged in to my servers
    • This particular script shows users who have running processes on the system, including service accounts that are running services.
      
      Instead you likely want to use this other script that I link to:
      https://gallery.technet.microsoft.com/scriptcenter/Find-the-logged-on-users-1161bd92 
      
      That one shows just the Explorer.exe process.
      
      Also you would likely want to make a small modification to the script, to add the SessionID.
      
      The sessionID works a little differently in different operating systems, however I *think* only sessionid 0 or 1 can be local.
      
      $Processinfo | ForEach-Object {  
                              New-Object PSObject -Property @{ 
                                  ComputerName=$Computer 
                                  LoggedOn    =$_.GetOwner().User 
                                  SID         =$_.GetOwnerSid().sid} 
                                  SessionId   =$_.SessionId} |  
                          Select-Object ComputerName,LoggedOn,SID,SessionId 
      
      What I recommend is actually using the PSterminalsservices module, that has some cmdlets for managing Terminal Services.
      
          # Get-TSSession is from @ShayLevy 
          # http://archive.msdn.microsoft.com/PSTerminalServices
      
  • How do you run the script
    2 Posts | Last post December 15, 2016
    • I am new to powershell, how do you runt the script
    • Here are some instructions that I had posted earlier down the page . ..
      
      step 1) Download the file and save it to a known location.
      step 2) right click on the script, select properties, then unblock.
      step 3) Open the powershell console (running as Administrator/elevated)
      step 4) 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 5) see if the function is loaded: Get-item function:\Get-LoggedOnUser
               or get-command Get-Loggedonuser
      step 6) call the function via: Get-LoggedOnUser -computername server123
      
  • No output
    1 Posts | Last post June 24, 2016
    • Thank you!
      I added a counter to count the number of detected users.
      
      .........
       $Computer = $_ 
      	$Count = 0
          try 
      ........
      
      ForEach-Object { $Count++;New-Object psobject -Property @{Computer=$Computer;LoggedOn=$_} } |  
      ........
      }#Forech-object(Comptuters)        
           IF($Count -le 0){
      	 	"No Logged in Users found" | Out-Host
      	}
      
      This gives me an output if nobody is logged in
      
      
      
      
      
      
      
      
      
      
  • Performance Improvement
    2 Posts | Last post June 09, 2016
    • Great script, but it was running quite slow. I modified to find logged on user on hundreds of computers, so couldn't take the slowness, then I had an idea, limit the Win32_process query to 'explorer.exe', and it helped a lot! About 4 times faster.
      
      Changed this line:
      $processinfo = @(Get-WmiObject -class win32_process -ComputerName $Computer -EA "Stop") 
      
      To:
      $processinfo = @(Get-WmiObject -class win32_process -ComputerName $Computer -Filter "Name='explorer.exe'" -EA "Stop") 
      
    • NB. You will also get accounts running services with this query.
      You can use the following script to only get users running the Explorer.exe process
      http://gallery.technet.microsoft.com/scriptcenter/Find-the-logged-on-users-1161bd92
  • Okay, I get "empty" output - nothing, nada, zilch
    4 Posts | Last post March 18, 2016
    • 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
      
    • Same here - I get no output on a system with PS 3.0 and PS 4.0.  I wonder if this will only work on a 2.0 system.
    • step 1) Download the file and save it to a known location.
      step 2) right click on the script, select properties, then unblock.
      step 3) Open the powershell console (running as Administrator/elevated)
      step 4) dot source the file/function into memory:   * you missed this step.
      . c:\fullpath\Get-LoggedOnUsers.ps1
      That is dot, then a space, then the full path to the file, then press enter.
      step 5) see if the function is loaded: Get-item function:\Get-LoggedOnUser
               or get-command Get-Loggedonuser
      step 6) call the function via: Get-LoggedOnUser -computername server123
  • 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             
      [CmdletBinding()]             
      Param (                        
      	[Parameter(Mandatory=$true, 
      	   Position=0,                           
      	   ValueFromPipeline=$true,             
      	   ValueFromPipelineByPropertyName=$true)]          
      	[String[]]$ComputerName 
      )#End Param 
       
      Begin {             
      	Write-Host "`n Checking Users . . . " 
      	$i = 0             
      }#Begin     
      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)        
      }#Process 
      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.
1 - 10 of 22 Items