Created
June 24, 2022 08:06
-
-
Save imtrinity94/31858f4c6395366c6c3ea2c5145bf05c to your computer and use it in GitHub Desktop.
Decode vSphere License using vRO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @version 0.0.0 | |
* @description Decodes the 'Product Name' and 'Product Version' from a vSphere license string | |
* | |
* @param {VC:SdkConnection} vCenterConnection | |
* @param {string} licenseKey | |
* | |
* @outputType string | |
* | |
*/ | |
//validate that we have a license key that is 5, 5 character strings delimited by a '-' | |
var licenseParts = licenseKey.split('-'); | |
if (licenseParts.length != 5) { | |
throw("license key is not complete"); | |
} | |
for (var part in licenseParts) { | |
if (licenseParts[part].length < 5) { | |
throw("license key is invalid. Section: '"+licenseParts[part]+"' of '"+licenseKey+"' is too short"); | |
} | |
if (licenseParts[part].length > 5) { | |
throw("license key is invalid. Section: '"+licenseParts[part]+"' of '"+licenseKey+"' is too long"); | |
} | |
} | |
var licenseInfo = vCenterConnection.licenseManager.decodeLicense(licenseKey); | |
System.log("License Name: "+licenseInfo.name); | |
var licenseProps = licenseInfo.properties; | |
for (var lp in licenseProps) { | |
if (licenseProps[lp].key === "ProductName") { | |
System.log("Product Name: "+licenseProps[lp].value); | |
} else if (licenseProps[lp].key === "ProductVersion") { | |
System.log("Product Version: "+licenseProps[lp].value); | |
} | |
} | |
/* Example Output | |
License Name: vSphere 7 Enterprise Plus | |
Product Name: VMware ESX Server | |
Product Version: 7.0 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment