Skip to content

Instantly share code, notes, and snippets.

@NamedJason
Last active December 1, 2015 16:21
Show Gist options
  • Save NamedJason/6bc3045aee9f7bae7888 to your computer and use it in GitHub Desktop.
Save NamedJason/6bc3045aee9f7bae7888 to your computer and use it in GitHub Desktop.
Change many ESXi Host root Passwords
#Description: Changes ESXi Host root passwords for all specified ESXi Servers
#Author: Jason Coleman
#Website: http://virtuallyjason.blogspot.com/
#Reference: http://virtuallyjason.blogspot.com/2015/10/batch-changing-esxi-root-passwords.html
#Usage: change-passwords.ps1 -oldPass <old root password> -passString <new root password>
param
(
$passString = "StrongPassword" + '<_<">_>',
$oldPass = "WeakPassword",
$hostPrefix = "sac-esx",
$hostSuffix = ".lab"
)
$hostsChanged = @()
$allHosts = get-vmhost $hostPrefix*$hostSuffix | sort
$allHosts | foreach {
connect-viserver $_ -user root -password $oldPass
set-vmhostaccount -useraccount (get-vmhostaccount root) -password $passString
$hostsChanged += "Host $($_.name) has been assigned the password of $passString"
cmd /C pause
}
$hostsChanged
@timmywong2726
Copy link

Once i do the password reset, do i need to update the password on vcenter?

@NamedJason
Copy link
Author

Sorry, I didn't see this question here earlier. No, you don't have to update the password on vCenter. When you add an ESXi host to vCenter, it creates its own local account on the ESXi host with a randomized password. That's one of the reasons why a given ESXi host cannot be managed by multiple vCenter servers; when you add it to a new vCenter server, that server generates a new password for the management account.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment