WilliamLam.com

  • About
    • About
    • Privacy
  • VMware Cloud
  • Tanzu
    • Application Modernization
    • Tanzu services
    • Tanzu Community Edition
    • Tanzu Kubernetes Grid
    • vSphere with Tanzu
  • Home Lab
  • Nested Virtualization
  • Apple
You are here: Home / Automation / How to forcefully disconnect a vSphere VM Console session?

How to forcefully disconnect a vSphere VM Console session?

06.24.2022 by William Lam // Leave a Comment

The vSphere Virtual Machine Console UI is an extremely useful interface for interacting with a VM, especially for initial configurations and/or debugging and troubleshooting purposes, such as an issue with networking. The VM console is analogous to connecting a physical keyboard and monitor to a computer, you remember the good ol' days right? 😀

Unlike the physical world, where you can only have a single person interacting with the computer, the vSphere VM Console can allow multiple users to view and interact with the VM. It is also not uncommon for customers to limit the number of simultaneous VM Console sessions, especially for security and/or for privacy purposes.


One potential down side with limiting the VM Console session to one is that another user may not be able to connect until the other session has concluded and/or has expired due to lack of activity. This recently came up as a question from a customer asking if there was a way to forcefully disconnect an existing VM Console connection?

I was not aware of any practical methods but pinging one of our Engineers, I came to learn that we actually had introduced a new vSphere API that would assist in this very use case and was introduced back in vSphere 7.0 Update 1. The new vSphere API is called DropConnections(), which is very straight forward to use and can disconnect one or more existing VM Console connections. To list all active VM Console sessions, another new vSphere API was introduced called QueryConnections().

To demonstrate these two new vSphere APIs, I will be using PowerCLI to invoke the vSphere API using a VM in my environment called ph-clone.

(Get-VM -Name ph-clone).ExtensionData.QueryConnections()

As you can see from the command above, the QueryConnections() API is performed on a specific VM and the results is a set of connection(s) with three fields: Label, Client and UserName.


Note: The UserName for vSphere H5 Client VM Console will always show up as root and for any Standalone VMRC VM Console, the UserName will simply show up as VNC User, which can help distinguish the type of method used to connect to VM Console.

To disconnect a specific VM Console connection, we will need the three fields from above as they are all required to identify a specific VM Console session to perform the disconnect

The DropConnections() API can disconnect a list of active VM Console session and in the example below, we are simply disconnecting a single session.

$connection = New-Object VMware.Vim.VirtualMachineConnection
$connection.Label = "4"
$connection.Client = "192.168.30.3"
$connection.UserName = "root"

(Get-VM -Name ph-clone).ExtensionData.DropConnections(@($connection))

If the VM Console session disconnect was successful, you will get a result of True as shown in the screenshot below.


If you navigate to the existing VM Console session that you had been opened prior, you will see the following when it is remotely disconnected using this API.


If you are ever in a crunch and needing to disconnect an active VM Console, this is definitely a handy vSphere API to be aware of! If you are not running vSphere 7.0 Update 1, one other method that can be used to quickly disconnect VM Console session(s) is by performing a vMotion of the VM, this has been used by few customers in the past.

Note: Although Standalone VMRC VM Console connections are listed in QueryConnections() API and can be disconnected using DropConnections() API, the VMCR client has built-in session re-establishment, so you will see that a new session is spawn even when you attempt to disconnect an active session.

More from my site

  • Blocking vSphere HTML5 VM Console and allowing only Standalone VM Remote Console (VMRC)?
  • How to audit vSphere Standalone VMRC or HTML5 VMRC connections?
  • How to restrict access to both the Standalone VMRC & HTML5 VM Console?
  • Standalone VMRC (VM Remote Console) re-introduced in vSphere 5.5 Update 2b
  • VMware Cloud on AWS 1.13 adds support for VMRC vCenter Proxy

Categories // Automation, vSphere 7.0 Tags // vm console, vmrc, vSphere 7.0 Update 1

Thanks for the comment! Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Search

Author

William Lam is a Senior Staff Solution Architect working in the VMware Cloud team within the Cloud Infrastructure Business Group (CIBG) at VMware. He focuses on Cloud Native technologies, Automation, Integration and Operation for the VMware Cloud based Software Defined Datacenters (SDDC)

Connect

  • Email
  • GitHub
  • LinkedIn
  • RSS
  • Twitter
  • Vimeo

Recent

  • Changing the default HTTP(s) Reverse Proxy Ports on ESXi 8.0 03/22/2023
  • Quick Tip - How to download ESXi ISO image for all releases including patch updates? 03/15/2023
  • SSD with multiple NVMe namespaces for VMware Homelab 03/14/2023
  • Is my vSphere Cluster managed by vSphere Lifecycle Manager (vLCM) as a Desired Image or Baseline? 03/10/2023
  • Interesting VMware Homelab Kits for 2023 03/08/2023

Advertisment

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy

Copyright WilliamLam.com © 2023

 

Loading Comments...