ESXi root password is Loss and Create New Admin Account

Log in with administrator access to vCenter, so instead of changing the root password thru PowerCLI.

PowerCLI to create an additional admin on the host for the troubleshooting, using this script:

#connect to the vCenter
connect-viserver <vCenter FQDN>

#get the ESXi host
$vmhost = get-vmhost -name <ESXi host FQDN>

#connect to the "esxcli" command environmant
$esxcli = Get-EsxCli -VMHost $vmhost -v2

#create temp user
$arguments = $esxcli.system.account.add.CreateArgs()
$arguments.id = 'tempuser'
$arguments.password = 'TempPass1!'
$arguments.passwordconfirmation = 'TempPass1!'
$esxcli.system.account.add.Invoke($arguments)

#Set tempuser to Admin
$arguments = $esxcli.system.permission.set.CreateArgs()
$arguments.id = 'tempuser'
$arguments.role = "Admin"
$esxcli.system.permission.set.Invoke($arguments)

NOTE: Please understand what the script is doing, you are using this script at your own risk, so please test it before using it.

After this, I could connect to the ESXi host, and do the troubleshooting, and after finishing this, I deleted the user again, since I used the wrong password for this, and not leaving a user on the host that the service provider is not aware of.

NOTE: It’s a good idea to remove the user afterwards again, this can also be done thru PowerCLI


#connect to the vCenter
connect-viserver
#get the ESXi host
$vmhost = get-vmhost -name
#connect to the "esxcli" command environmant
$esxcli = Get-EsxCli -VMHost $vmhost -v2
#remove tempuser
$arguments = $esxcli.system.account.remove.CreateArgs()
$arguments.id = 'tempuser'
$esxcli.system.account.remove.Invoke($arguments)