Last week I received a question about retrieving the expiration date for vSphere licenses in vCenter Server which can be seen in both the vSphere Web Client and vSphere C# Client under the Licensing section. Even though there are vCenter alarms that monitor license usage and compliance, it still makes sense that users may still want to be proactively monitoring their license keys for expiration and ensuring they are renewed in a timely manner.
I provided a quick sample script to the user but thought I might as well clean it up a bit and share it with the rest of the VMware community. I also wanted to provide some additional details on where to look for the expiration details as well as other information pertaining to licenses in vSphere.
To access anything related to licensing in the vSphere API, there is something called the LicenseManager object which provides methods to add/remove licenses from vCenter Server or an ESXi host as well as various properties about the licenses currently registered. To view all license in the system, there is a property called licenses which contains detailed information about each license such as the name, license key, unit cost, used, etc. You will notice, there are no properties for expiration date or the features that is enabled for each of these licenses. The reason for this is that this additional information is stored in a property called properties which be any key/value pair and depending on the license, you will see a list of different values.
To get the list of keys and their associated values which could be additional key/value pairs, you would need to iterate through the properties array and then extract out keys that are relevant to your search. Since we are interested in the expiration of a particular license, the keys that we want to search for are expirationDate, expirationMinutes and expirationHours. There are of course other keys that may be of interest, such as features which provides a specific vSphere capability that is available within a license key.
Armed with this information, here is a sample vSphere SDK for Perl script called getLicenseInfo.pl that leverages the LicenseManager and the license properties to extract out all the licenses in either a vCenter Server or standalone ESXi host and provides details on each license including the expiration date.
Disclaimer: These script are provided for informational/educational purposes only. It should be thoroughly tested before attempting to use in a production environment.
This script can be executed against a vCenter Server or an ESXi host and by default it will not display the license key unless you set the –hide_key parameter to false. Here is a screenshot of what you would see which includes the name of the license, current total count, used and calculated remainder and of course the expiration date, hours and minutes.
If you are interested in a similar script but using PowerCLI, here is a script written by my colleague Alan Renouf which exports the licenses to an excel spreadsheet. You can of course easily modify either the vSphere SDK for Perl script or PowerCLI script to periodically monitor the expiration dates and proactively send out reminders to renew your vSphere licenses.
Get notification of new blog postings and more by following lamw on Twitter: @lamw