Skip to content

Instantly share code, notes, and snippets.

@AfroThundr3007730
Created March 20, 2020 03:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AfroThundr3007730/3b1824f2d968febc1b2d0c72af39d252 to your computer and use it in GitHub Desktop.
Save AfroThundr3007730/3b1824f2d968febc1b2d0c72af39d252 to your computer and use it in GitHub Desktop.
Mass change ESXi host passwords to new values
# Mass change ESXi host passwords to new values
# The hashtable should have an entry for every host
# Ensure $host_creds doesn't end up in your history
Connect-VIServer -Server 'YOUR_VCSA' -Credential (Get-Credential)
$host_creds = @{
'ESXi1.lab.local' = 'VALUE_FROM_PW_DB';
'ESXi2.lab.local' = 'VALUE_FROM_PW_DB';
# More as needed...
}
$old_pw = Get-Credential
ForEach($name in ((Get-VMhost).name | sort)) {
Write-Host "Changing password for $name to $($host_creds[$name])"
Connect-VIServer -Server $name -Credential $old_pw -NotDefault
Set-VMHostAccount -Server $name -UserAccount 'root' -Password $host_creds[$name]
}
ForEach($name in ((Get-VMhost).name | sort)) {
Write-Host "Verifying password for $name"
$secure_pw = ConvertTo-SecureString $host_creds[$name] -AsPlainText -Force
$new_cred = [PSCredential]::New('root', $secure_pw)
Connect-VIServer -Server $name -Credential $new_cred -NotDefault
Get-VMHostAccount -Server $name -User 'root'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment