vRO JS Code to create ESXi root and non root accounts
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 1.0.0 | |
* | |
* @param {VC:HostSystem} host | |
* @param {string} localUserName | |
* @param {SecureString} localUserPassword | |
* @param {string} accessMode | |
* @param {string} localUserDescription | |
* | |
* @outputType void | |
* | |
*/ | |
function createEsxiLocalUser(host, localUserName, localUserPassword, accessMode, localUserDescription) { | |
if(!host) throw "host parameter not set"; | |
if(!localUserName || !localUserPassword) throw "Either username or password parameter not set"; | |
if(!localUserDescription) localUserDescription = "***Account created using vRO***"; | |
if(localUserDescription.indexOf(localUserPassword) != -1) throw 'Weak Credentials! Avoid putting password string in description'; | |
// Retrieve all system and custom user accounts | |
var arrExistingLocalusers = host.configManager.hostAccessManager.retrieveHostAccessControlEntries(); | |
var accountSpecs = new VcHostAccountSpec(localUserName,localUserPassword,localUserDescription); | |
host.configManager.accountManager.createUser(accountSpecs); | |
switch(accessMode){ | |
case 'Admin': //Full access rights | |
host.configManager.hostAccessManager.changeAccessMode(localUserName,false,VcHostAccessMode.accessAdmin); | |
break; | |
case 'ReadOnly': //See details of objects, but not make changes | |
host.configManager.hostAccessManager.changeAccessMode(localUserName,false,VcHostAccessMode.accessReadOnly); | |
break; | |
case 'NoAccess': //Used for restricting granted access | |
host.configManager.hostAccessManager.changeAccessMode(localUserName,false,VcHostAccessMode.accessNoAccess); | |
break; | |
default: //No access assigned. Note: Role assigned is accessNone | |
host.configManager.hostAccessManager.changeAccessMode(localUserName,false,VcHostAccessMode.accessNone); | |
} | |
System.warn(" >>> Local user "+localUserName+" created with accessMode "+accessMode+" on host "+host.name); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Know more at https://cloudblogger.co.in/2022/12/22/create-esxi-root-account-with-vro-cb10104/