Created
March 20, 2020 03:32
-
-
Save AfroThundr3007730/3b1824f2d968febc1b2d0c72af39d252 to your computer and use it in GitHub Desktop.
Mass change ESXi host passwords to new values
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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