Reset Password for root account of ESXi Server using PowerCLI
search cancel

Reset Password for root account of ESXi Server using PowerCLI

book

Article ID: 376979

calendar_today

Updated On:

Products

VMware vSphere ESXi

Issue/Introduction

Lost/forgotten password for "root" account on ESXi Server can be reset using Host Profile based approach as outlined in Reset ESXi Root Password with Host Profile

If the vCenter Server license doesn't allow the use the Host Profiles, password reset for ESXi Server managed by vCenter Server can be performed using PowerCLI

Resolution

If PowerCLI is not already installed in the environment follow the Installation Guide to install it.

Reset the password for "root" user following steps as outlined below 

  1. Open PowerShell Session
  2. Connect to the vCenter Server:
  3. Setup a new Credential Object running following command. Please use a strong password meeting the requirements
    $creds = Get-Credential -UserName "root" -Message "Enter root as username and new password"
  4. Get a reference to the ESXi Server on which you need to change the root user password
    $esxiserver = Get-VMHost -Name ESXI_NAME_FROM_VC_INVENTORY
    • Replace ESXI_NAME_FROM_VC_INVENTORY with the inventory name of the ESXi Server for which you need to reset the password
  5.  Get a reference to ESXCli system of the ESXi Server
    $esxcli = Get-EsxCli -VMHost $esxiserver -V2
  6. Create the argument for updating the root user account
    $userarg=$esxcli.system.account.set.CreateArgs()
    $userarg.id=$creds.UserName
    $userarg.password=$creds.GetNetworkCredential().Password
    $userarg.passwordconfirmation=$creds.GetNetworkCredential().Password
  7. Set the password running the esxcli command
    $esxcli.system.account.set.invoke($userarg)
  8. Above execution will return "true" if the reset if success

Additional Information

Please note that this method doesn't validate the quality of the password used during the execution. Any such validation will happen at the ESXi Server when the command to reset it sent via ESXCli.

This method works only for ESXi Server that are managed by vCenter Server and NOT in "Disconnected" or 'Not Responding" State.