Menu

Virtual Geek

Tales from real IT system administrators world and non-production environment

Reset VMware ESXi root password from vCenter using PowerCLI

When I began working with a new client on their Virtualization Broadcom VMware project, I encountered several ESXi servers that were already deployed and connected to vCenter servers. Since I was new to the project, I found that the root passwords for some of these ESXi servers were undocumented and unknown.

In certain cases, I needed the root password to log in and retrieve low-level information from these servers. Fortunately, if an ESXi server is connected to vCenter, it's possible to reset the root password using VMware PowerCLI, which allowed me to address the issue without direct access to the initial credentials.

Powercli vmware broadcom esxcli esxi vcenter reset root password without error configuration automation.png

Here’s a streamlined description of the script steps for resetting an ESXi root password via PowerCLI:

  1. Import the PowerCLI Module: Begin by importing the VMware.PowerCLI module in PowerShell.
  2. Connect to vCenter: Establish a connection to the vCenter server by logging in with the appropriate credentials.
  3. Specify ESXi Host Details: Identify the ESXi host for which you need to reset the password. Typically, you will use the host name as it appears in vCenter. Specify the username (usually "root") and the new password.
  4. Retrieve ESXi Information and Establish Connection: Use Get-VMHost to get ESXi host information, then create an EsxCli object using Get-EsxCLI to interact with the host.
  5. Reset the Password: With the esxcli system account command, you can list and set the new password for the root account.
  6. Verify Success: After successfully setting the password, a confirmation message (true) will appear, indicating the password reset was successful.

This process provides an efficient way to reset an ESXi root password for servers connected to vCenter, without needing prior knowledge of the current password.

$vcenter = 'vcenter_ip_fqdn'
$vcenterUser = '[email protected]'
$vcenterPassword = 'P@55w0rd'

Import-Module VMware.VimAutomation.Core
Connect-Viserver -Server $vCenter -User $vcenterUser -Password $vcenterPassword

###############################################################

$esxiName = 'esxi_name_from_vCenter'
$esxiUserName = 'root'
$esxiNewPassword = 'P@55w0rd'

$esxi = Get-VMHost | Where-Object { $_.Name -eq $esxiName }

$esxcli = $esxi | Get-EsxCLI -V2

$rootUser = $esxcli.system.account.list.Invoke() | Where-Object { $_.UserID -eq $esxiUserName }

$userArg = $esxcli.system.account.set.CreateArgs()
$userArg.id = $rootUser.UserID
$userArg.password = $esxiNewPassword
$userArg.passwordconfirmation = $esxiNewPassword
$esxcli.system.account.set.Invoke($userArg)

Useful Articles
Esxi reset root password, reset windows administrator passwordReset forgotten ESXi root password on Domain joined Esxi using vSphere web client and Powercli
Reset ESXi root password using Host Profiles on vCenter server: VMWare vSphere Web client

Resolved: Reset Esxi forgotten root password using hiren bootCD step by step
PART 1 : INSTALLING ESXI ON VMWARE WORKSTATION HOME LAB 
PART 2 : CONFIGURING ESXI ON VMWARE WORKSTATION HOME LAB 
PART 3 : ACCESSING STANDALONE ESXI SERVER IN HOME LAB USING VSPHERE CLIENT 
Create bootable USB from ISO file
Adding and sharing RDM disk to multiple VMs in VMware step by step
Upload files to vmware ESXi datastore: Different methods
How to convert RDM disk (Raw Device Mapping) to VMDK
Find Dell iDrac, HPE ilo IPMI ip address on VMware ESXi
Reset Dell iDRAC password from ESXi server
Install Update VIB Zip files software on VMware ESXi server
Uninstall Remove VIB software from ESXi server

Go Back

Comment

Blog Search

Page Views

12279006

Follow me on Blogarama