How to see which session has the Remote Console opened in VMware! (GUI and PowerCLI!)

September 15th, 2014
by Christopher Kusek (PKGuild)

So you ever been in that situation where you either see a message like,

Number of active connections has changed. There are now 2 active connections to this console


Unable to connect to the MKS: Console access to the virtual machine cannot be granted since the connection limit of ‘x’ has been reached.”  (This second one is most likely to come up when you have either a STIG or security defined limitation to the number of remote connections to use, thus by default you’re more likely to see message #1!)

Well, the question is… What do you do in these circumstances? You might ask yourself, “Damnit! Who is the other person connected!”   When looking for this answer you may come across responses in the forums such as:

  • Just use tsadmin to login to the server to see who else is logged in
    • Great if you’re on windows, but that doesn’t tell you show OWNS the SESSION
  • ssh into the box to see who else is logged in
    • Wow it’s like you’re not getting it. What if they’re not logged in, but simply sitting at the login prompt? I hear fail…
  • Use arbitrary application to arbitrarily see who is logged in!
    • Okay, seriously? (Yes I’ve seen NUMEROUS responses like this, which refer to lots of applications, and don’t solve the problem…)

Well, guess what, I don’t like these answers, which prompted me to write this blog post, thus I’ll show you how to do it via the GUI (Very Easy…) and also via PowerCLI because we love PowerCLI! Disclaimer: I do not show how to do this using the VMware Web Client, because I personally hate the web client, so if you’d like to document that part, go for it. :)

Checking for Remote console connected in the GUI!


So within the handy GUI from within a Virtual Machine (In this context I use the UI VM for vCOPS…) Just click on the “Tasks & Events” tab and you’ll notice the entry below, “Remote console connected” looking at the timestamp you’ll be able to note which user it was which connected and at what time.  Thus if this user doesn’t need to be logged into the console you can go kill their session as needed. Easy Peasy, right?! :)

Checking for Remote console connected using PowerCLI!!!

This one is just as easy if not easier, especially if you want to modify this script ultimately to query lots of objects, or you can even modify it to see which particular sessions a particular user has opened, that is outside the scope of THIS blog post, but nonetheless, here is the syntax!

Get-VM %VMNAME% | Get-VIEvent | Where {$_.Gettype().Name -eq "VMRemoteConsoleConnectedEvent"} | Select UserName, CreatedTime, FullFormattedMessage

What you have here is a Get-VM looking at a specific Virtual Machine (You supply) then it will pull up from that VM or VMs the Remote Console Connected event, After which point PowerCLI will dump the results of the Username connected, what time they did, and the FullFormattedMessage (Which I mainly have in there for errorchecking, you can omit if you’d like)

But lo and behold, BOOM you’re done! Hopefully this was easy for you, if you’d like there are a lot of VERY long and VERY complex scripts which do the EXACT same thing, but you know how I feel about One-Liners. :)

Good luck and stay Physical, VIRTUAL I MEAN VIRTUAL, OMG!

Tags: , , , , ,
Posted in PowerCLI, Virtualization, vmware, vSphere | Comments (5)

  • James Cook says:

    Hi, thank you for sharing this, very useful! Is there a way to use Get-VM to first check every VM in a Vcenter for console sessions and then query those VM’s for the user connected?

  • James Cook says:

    Thanks very useful… is there a way to use this to check every VM on a Vcenter and export to excel?

  • Technically you should be able to do that James… You may want to try executing the script as “Get-VM * and see if it provides the information you’re looking for, and then export it to CSV as appropriate for review

  • Rakesh Varma says:

    How do you disconnect that console session opened by another user

    • Archives