get-loggedonuser function

Powershell function to get the logged on users on a local or remote computer, with session information.

4.1 Star
Add to favorites
E-mail Twitter Digg Facebook
Sign in to ask a question

  • Possible to get clientname and IP?
    1 Posts | Last post November 28, 2018
    • Have 4 RDS servers and managing them from one broker, problem is when it's thinclients connecting I need to know the IP to help them outside the shadow function in RDS
      Really missing this feature from TS GUI in 2008 R2 kernel based TS
  • filtering out unwanted logons
    2 Posts | Last post December 12, 2016
    • Could someone help me filter out some of the logons? i'm only looking for the logon types of interactive and the auth type of kerberos.
    • Try:
      get-loggedonuser -computername "server" | where {$_.type -eq "interactive" -and $_.auth -eq "Kerberos"}
  • Help with this script..
    2 Posts | Last post December 12, 2016
    • I'm a noob. Your script seems really good but I have no idea how to run it. I saved the whole code as get-loggedonuser.ps1 on my desktop and when i ran it  from powershell it didnt do anything. Any idea what could i be doing wrong? Am i supposed to modify somethng within the script ? Can you give me proper steps how to run this script for remote servers ?
    • You didn't run it with the required parameter -ComputerName.  Try it again like so:
      get-loggedonuser -computername "server"
  • Windows Server 2012
    1 Posts | Last post March 15, 2013
    • Good function, thank you!
      Test on Windows Server 2012 passed successfully
  • Duplicate results
    1 Posts | Last post December 13, 2011
    • I am getting a lot of duplicate results. Is there a way to only return unique values? I'm trying to query our Remote Desktop Servers to determine which RDS server a user is logged on, or all the logged on users for all our RDS servers. I tried using Sort-Object -Unique to filter the duplicate values but that didn't seem to work. Suggestions?
  • Format?
    2 Posts | Last post September 13, 2011
    • jrv
      Nice piece of code.  
      Too bad this isn't a Wiki or I would fix the indenting so it is readable.
    • I'll work on that.  
      Do you think I should re-write it for V2, or leave it as-is so it's backward compatible?
  • Help With Function
    3 Posts | Last post April 25, 2011
    • I must be missing something.  I usually work with the OpSys and if I need something I either go at it log form or else build a batch file to do what I need.  Now that we have finally cleared the last of our 2003/2000 boxes and rid ourselves of XP I want to move on and use PowerShell but I am finding a whole new barrel of problems.  The simplest one is that with these scripts like yours that start with the Function statement, I can't seem to make them work.
      I start PowerShell then I enter the name (GetLoggedUser.ps1) or run that with the machinename, the -computer machinename, just about every way I can try and nothing seems to happen.  So when using a script like these how do you start them?  Looking at the response you did regarding multiple servers in the domain using a $serverlist, I tried to create a file with a couple of computer names and did as you have if listed but no luck.  Am I missing something so simple?
    • If you want to load a function from a file into your current PS session, you need to dot source it into the current scope, like this:
       PS C:\scripts>. ./get-loggedonuser.ps1
      this will return you to a prompt, but appear to have not done anything. What it did was load the function into the current scope so it can be used, like this:
      PS C:\scripts>get-loggedonuser computer1
      The easist way to make it available without having to load it is to put it in your profile.  Run this:
      PS C:\>notepad $profile
      That will open your profile in notepad, then just paste the script in at the bottom of your profile, save it.  Then every time you launch a PS session, that function should already be loaded and ready to use.  You can use get-command to verify what functions are loaded into the session.  
    • WOW - lots more than I thought.  So first I need to remember to save the file with the same name as the command then load the command.  Not bad.
      Did just as you said and it works great.  So time to learn some more but I can't thank you enough for the assistance.
  • Quick Question
    4 Posts | Last post January 05, 2011
    • Can this function be used to queary all member servers in a particular domain?
    • You could foreach a list of server through it:
      $serverlist |% {get-loggedonuser $_}
      What did you have in mind?
    • That actually worked really well. What I had in mind would have taken forever to execute on an enterprise the size I work with. I just got a list of servers from the user and used that list against this function and found three servers he was logged into that was causing his lock out issues. Thanks, awesome bit of code
    • Cool!  Glad you got it to work.  I also use it to find out who's hogging the RDP sessions on a server I want to get into.