Get-LoggedOnUser Gathers information of logged on users on remote systems

This script utilizes quser to query either the local or remote system and parses this into PowerShell objects using the ConvertFrom-Csv Cmdlet. It supports pipeline input or an array of computers in the ComputerName parameter.

 
 
 
 
 
4.9 Star
(21)
28,019 times
Add to favorites
9/23/2015
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Display "ClientName"
    3 Posts | Last post October 11, 2017
    • On the Sessions tab in Remote Desktop Services Manager there is a "ClientName" column. Is there a way to capture that as well?
    • Hello Patrick,
      
      Yes this is possible, I have opened up a GitHub issue so you can track my work on this request, it is available here:
      
      
      https://github.com/jaapbrasser/SharedScripts/issues/12
      
      
      Regards,
      
      Jaap Brasser
    • Add Servername line by line to ServerList.txt :
      $computername = Get-Content  C:\Scripts\Loggedonuser\ServerList.txt
      
      View On Screen :
      .\Get-LoggedOnUser –computername $computername | ft -AutoSize
      
      View as CSV file : 
      .\Get-LoggedOnUser –computername $computername | export-csv C:\Scripts\Loggedonuser\LoggedonUuers.csv -NoTypeInformation
      
      View as HTML file :
      .\Get-LoggedOnUser –computername $computername| ConvertTo-HTML | Out-File C:\Scripts\Loggedonuser\LoggedonUuers.html
  • how will i run it to multiple machines?
    1 Posts | Last post February 25, 2017
    • Im new to powershell.
      
      How do run it so I can get the result for all the machines and their computer name as well? 
      Thanks,
      LAdee 
  • How to send it as Mail?
    2 Posts | Last post February 14, 2017
    • Hello Jaap,
      
      THX for the Script, is there a way to send it as E-Mail?
      
      Cheers
      Mike
    • Hello Mike,
      
      Absolutely, you could use the Send-MailMessage cmdlet for this purpose, for example:
      
      $EmailSplat = @{
          To          = 'mike@yourserver.com'
          From        = 'jaapbrasser@yourserver.com'
          SmtpServer  = 'smtp.yourserver.com'
          Subject     = 'Logged on users Reports from server X'
          Body        = .\Get-LoggedOnUser.ps1 | Out-String
      }
      Send-MailMessage @EmailSplat
      
      
      Let me know how that works for you!
      
      
      Regards,
      
      Jaap Brasser
  • idletime=none
    2 Posts | Last post February 14, 2017
    • Hi Jaap,
      
      some computer returns "none" for idletime.
      What is the meaning of this ? 
      
      Thanks
    • Hello Onimamoglu,
      
      This means the session is currently active, if this is the case it can be listed as none or as ., depending on the operating system.
      
      
      Regards,
      
      Jaap Brasser
  • Displaying idle time to user?
    2 Posts | Last post November 03, 2016
    • Found this article while looking for something a bit different but hoping you have an answer or suggestion for me. In my business we have like 20 admins and logging on to 200+ servers, you 1) don't know if you just happened to disconnect someone else 2) cannot tell how long stuff that is open on that server has been idle. I was hoping to find a way to display how long the session was idle before I connect to be able to tell if someone is working or if that stuff was just forgotten open on the server 2w ago. 
    • Hello Borgsquirrel,
      
      This script displays both the logon time and the idle time, would that not provide you with enough information? Here is an example of the output of this script:
      
      UserName     : jbrasser
      ComputerName : localhost
      SessionName  : rdp-tcp#0
      Id           : 2
      State        : Active
      IdleTime     : .
      LogonTime    : 11/3/2016 9:37 AM
      Error        :
      
      UserName     : otheradmin
      ComputerName : localhost
      SessionName  : rdp-tcp#2
      Id           : 3
      State        : Active
      IdleTime     : 14:47
      LogonTime    : 9/27/2016 11:41 AM
      Error        :
      
      So this displays how long a user has been idle, unfortunately this does not display how long the processes that the user are running have been idle. This is something that does not have a clear answer either. If it is something simple, like a file transfer you can simply track disk activity for processes by that user.
      
      In general I would advise on using PowerShell Remoting capabilities for server management where possible, then RDP logons are not required and you won't have to disconnect your colleagues.
      
      
      Regards,
      
      Jaap Brasser
  • html
    4 Posts | Last post September 01, 2016
    • Hi Jaap,
      
      Is it possible to send the result of this script as an html file with e-mail
      
      Thanks
    • Absolutely, you could chose to either attach it to the email or send it as the body of an html email, the following example shows how to insert it into the body of an email:
      
      Send-MailMessage -From me@jaapbrasser.com -To colleague@jaapbrasser.com -Subject 'Your loggedon users HTML report' -SmtpServer smtp.jaapbrasser.com -BodyAsHtml -Body (.\Get-LoggedOnUser.ps1 | ConvertTo-Html)
    • Hi Jaap,
      
      Thanks for the reply,
      
      I did add the line you send to the end of Get-LoggedOnUser.ps1 but get the error:
      
      Unexpected token 'Send-MailMessage' in expression or statement.
      
      I did also try to run the it from shell and get en error.
      
      Any idea?
    • Which version of PowerShell are you running, can you show the output of the following code:
      $PSVersionTable
      
      Also can you copy paste the entire line of code you are executing and the complete error message, that way I'll be able to examine what's causing the issue.
      
      
      Regards,
      
      Jaap Brasser
      
      
  • Output as CSV and email to admin
    2 Posts | Last post July 13, 2016
    • Hi Jaap,
      
      Could you please let me know how to output the data to a CSV file and get it emailed to admin?
      
      Thanks
      Yagya Shree
    • Sure, you could output it to csv using the following command:
      
      .\Get-LoggedOnUser.ps1 | Export-Csv 'C:\Script\YourFile.Csv'
      
      If you would like to email this you could do something along these lines:
      
      Send-MailMessage -Attachments C:\Script\YourFile.csv -From me@jaapbrasser.com -To colleague@jaapbrasser.com -Subject 'Your CSV File' -SmtpServer smtp.jaapbrasser.com
  • Additional Functionality sought
    1 Posts | Last post January 07, 2016
    • Possible to have this script loop continuously until there are 0 users on the system and then reboot. I was thinking this could be a great tool for additional automation and this being the trigger for that to occur.
  • Question about this script
    2 Posts | Last post January 07, 2016
    • Get-Content ComputerList.txt | ForEach-Object { 
          .\Get-LoggedOnUser.ps1 -ComputerName $_
      } | Where-Object {@('Active','Disconnected') -contains $_.State} |
      Select-Object -ExpandProperty ComputerName
      
      
      If I want to do the above code, do I put that into another powershell script to run?
    • You could just paste this into the PowerShell console and execute it right away. If you expect to execute this more than once you could also store this as a .ps1 file with this code as its content.
  • Great script
    2 Posts | Last post November 23, 2015
    • Thanks for the script.   I would like to run this script and then export a list of server names but only ones that have active or disconnected sessions.
      
      Thanks
    • You could do something along these lines:
      
      Get-Content ComputerList.txt | ForEach-Object { 
          .\Get-LoggedOnUser.ps1 -ComputerName $_
      } | Where-Object {@('Active','Disconnected') -contains $_.State} |
      Select-Object -ExpandProperty ComputerName
11 - 20 of 29 Items