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
33,959 times
Add to favorites
E-mail Twitter Digg Facebook
  • Error
    1 Posts | Last post November 20, 2019
    • Hello, when I run script, I get an error: error 0x00000005 enumerating sessionnames.
      Thank you.
  • Getting this script to read a .txt or .csv
    2 Posts | Last post October 13, 2019
    • Great script, but for this to be any use to me I need it to have the ability to read a .txt or .csv file that has a list of my servers and then output to another .csv or .html. There was one solution below but it didn't work. when I use .\get-loggedonuser.ps1 .\serverlist.txt | export-csv .\getloggedonuser.csv -notypeinformation the error I get back is "A parameter can not be found that accepts argument 'l'. at line:1 char:1
    • Hello Robg77,
      You could run something like this:
      Get-Content -Path .\ServerList.txt | ForEach-Object {.\Get-LoggedOnUser.ps1 -ComputerName $_}
  • Run script referencing a file
    2 Posts | Last post October 13, 2019
    • Hi there, First of all thanks for creating the script. I am new to PowerShell and learning little each day. This script really helps in my daily task. Can I run the script referencing a text file that contains all the PC's in the network?
    • Hello CGLiving,
      Yes, assuming you have a text file with a computer name on each line you could run something like this:
      Get-Content -Path .\Servers.txt | ForEach-Object {.\Get-LoggedOnUser.ps1 -ComputerName $_}
      Let me know how that works for you!
  • Calling from batch file
    2 Posts | Last post February 09, 2019
    • I am trying to call from batch file.
      powershell.exe -file ".\Get-LoggedOnUser.ps1" -ComputerName "a123,b456" >> log.txt 2>&1
      However, when I run with 2 or more computer names, i get the following error.
      Error 0x000006BA enumerating sessionnames
      Works fine when I only pass in one computer name.
      Please advise!
    • Alright, simple solution...
      use command not file...
      powershell.exe -command ".\Get-LoggedOnUser.ps1" -ComputerName a123,b456 >> log.txt 2>&1
  • Format Table output
    1 Posts | Last post January 15, 2019
    • 3o4
      is it possible to format this as a table instead of list?
  • Add 'Display Name' Corresponding to Username
    4 Posts | Last post December 14, 2018
    • Great script! I am running your script with export to CSV to produce a nicely formatted output report that is very useful, e.g.:
      .\Get-LoggedOnUser.ps1 | Export-Csv .\Get-LoggedOnUser.csv -NoTypeInformation
      Would it be possible to add an additional column next to UserName with the corresponding Display Name?
      I tried adding a new variable DisplayName under the $HashProps section to convert the username to display name using Get-ADUser, similar to this:
      DisplayName = (Get-ADUser -Identity $session.UserName -Properties DisplayName).DisplayName
      But haven't been able to get it to work with the existing current line structure sequence... is there a way to add Display Name into your existing script structure?
    • Hello!
      Try this:
      DisplayName = (Get-ADUser -Filter * -Properties DisplayName | Where-Object {$_.sAMAccountName -eq $CurrentLine[0]}).DisplayName
    • More details:
      $HashProps = @{
          UserName = $CurrentLine[0]
          DisplayName = (Get-ADUser -Filter * -Properties DisplayName |
            Where-Object {$_.sAMAccountName -eq $CurrentLine[0]}).DisplayName
          ComputerName = $Computer
      Also, you need to add DisplayName property to 2 strings below:
      Select-Object -Property UserName,DisplayName,ComputerName,SessionName,Id,State,IdleTime,LogonTime,Error
    • perlestius, thank you very much!
      The DisplayName code that you suggested worked perfectly!
      Querying the Display Name properties from the $CurrentLine[0] object was the logic that I was missing. Thanks again for your very helpful response!
  • Get-LoggedOnUser from a non-domain joined computer
    1 Posts | Last post November 07, 2018
    • Hi Japp,
      Great code! 
      Can I run this script from a non-domain joined computer by passing my domain username/password. Similar to what I did below to get a user details with the surname of 'Taylor'.
      Import-Module ActiveDirectory
      $User = "remotedomain\myusername"
      $PWord = ConvertTo-SecureString -String "mypassword" -AsPlainText -Force
      $Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord
      Get-ADUser -Server remotedomain -Credential $Credential -Filter {Surname -like 'Taylor'}
      Can you please advise how I can pass my domain credentials and the remote domain into your script ?
      Many thanks,
  • Cater for username containing a space
    2 Posts | Last post August 01, 2018
    • Hi Jaap,
      Great script. Have you updated the script of late to cater for a user name that contains a space.  The split obviously of array items is therefore out of sequence.
      Thanks AjN3806
    • Changing...
      $CurrentLine = $_.Trim() -Replace '\s+',' ' -Split '\s'
      $CurrentLine = $_.Trim() -Replace ' {2,}',',' -Split ','
      ...caters for a Username containing a single space, but assumes there is always at least 2 spaces between columns.
  • I am getting output on my mail tried so many times it shows script failed due to call depth overflow
    1 Posts | Last post June 11, 2018
    • I am not getting output on my mail tried so many times it shows script failed due to call depth overflow
  • Prompt for Computer name?
    1 Posts | Last post December 29, 2017
    • SO how do I set this to prompt for the computer name that I would want to search, rather than manually drop it into the script each time? I know I have to set it up to ask for a value for $ComputerName, but I'm not sure what to add to do that.
      Otherwise, this script is awesome. Thank you!
1 - 10 of 30 Items