WilliamLam.com

  • About
    • About
    • Privacy
  • VMware Cloud Foundation
  • VKS
  • Homelab
    • Resources
    • Nested Virtualization
  • VMware Nostalgia
  • Apple
You are here: Home / Uncategorized / Identifying Idle vCenter Sessions

Identifying Idle vCenter Sessions

12.20.2011 by William Lam // 4 Comments

I recently received a question on how to identify idle vCenter sessions that may stem from a non-active vSphere Client or vSphere API connection. Properly managing sessions to your vCenter Server is as important as knowing who is logging in. If you exhaust the maximum number of connections, you can easily deny login access to other users and/or services that are needed to connect to vCenter Server which can lead to very bad things. In the worse case, you can even prevent administrators from logging into a new session to help terminate any stale/idle connections.

The vSphere API provides a sessionManagement manager to help you manage all sessions, including checking whether a session is still active and terminating a session. I wrote a quick vSphere SDK for Perl script called sessionManagement.pl which allows you to list all sessions for a given vCenter and terminating a a specific session. Every session has a unique sessionKey that the vCenter Server uses to track and it provides information such username, login time and last active which can be used to create an unattended script to automatically terminate sessions that have gone beyond a certain threshold.

Here is an example script output of performing the "list" operation:

Note: There maybe vCenter Plugins/Extensions that creates sessions such as CapacityIQ, those will be denoted by "vCenter Ext Session" field. These should not be terminated as it can negatively impact 3rd party applications.

Here is an example script output of terminating a specific session using the "disconnect" operation which you will need to specify sessionkey provided in the previous command:

For those of you that are interested in creating your own script to terminate idle sessions, you can use the DateTime Perl module to help with calculating the amount of idle time and comparing that to a pre-defined timeout value.

More from my site

  • An update on how to retrieve useful information from a vSphere login?
  • vSphere Session Timeout Overview
  • Do I need to install both the vSphere CLI & vSphere SDK for Perl?
  • Automate Enabling VM Storage Profiles Capability in vSphere
  • Automating VCSA Network Configurations For Greenfield Deployments

Categories // Uncategorized Tags // idle, session, vsphere sdk for perl

Comments

  1. *protectedGregg says

    05/18/2012 at 9:21 am

    Hi,

    I get the following error when executing:

    Undefined subroutine &UserSession::extensionSession called at sessionManagement.pl line 75

    Gregg

    Reply
    • *protectedWilliam says

      05/18/2012 at 3:26 pm

      @Gregg,

      The extensionSession property is only available in vSphere 5, I assume you're most likely connecting to a non-vSphere 5 environment. You can still leverage the script, but you'll need to comment out line #75 which will not print the "vCenter Ext Session"

      Reply
  2. *protectedGregg says

    05/24/2012 at 10:52 am

    Hi,

    Thanks, works like a charm - Really, really useful script!!!

    Thanks again
    Gregg

    Reply

Trackbacks

  1. Capacityiq Login - login link says:
    04/06/2021 at 1:10 pm

    […] Identifying Idle vCenter Sessions – virtuallyGhetto […]

    Reply

Thanks for the comment!Cancel reply

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

Search

Thank Author

Author

William is Distinguished Platform Engineering Architect in the VMware Cloud Foundation (VCF) Division at Broadcom. His primary focus is helping customers and partners build, run and operate a modern Private Cloud using the VMware Cloud Foundation (VCF) platform.

Connect

  • Bluesky
  • Email
  • GitHub
  • LinkedIn
  • Mastodon
  • Reddit
  • RSS
  • Twitter
  • Vimeo

Recent

  • Programmatically accessing the Broadcom Compatibility Guide (BCG) 05/06/2025
  • Quick Tip - Validating Broadcom Download Token  05/01/2025
  • Supported chipsets for the USB Network Native Driver for ESXi Fling 04/23/2025
  • vCenter Identity Federation with Authelia 04/16/2025
  • vCenter Server Identity Federation with Kanidm 04/10/2025

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 © 2025