Powercli Script to change ESXi root passwords

This is a little script to change the ESXi passwords for hosts in a cluster, you can add clusters the include variable and add ESXi hosts specifically to the exclude variable all separated by quotes and commas. It does have the password inbeded in this script but you  opt out of that and be prompted if preferred.


#Changing root password.</div>
<div>$usr = administrator@vsphere.local
$psd = pssword</div>
<div>Connect-VIServer vcenter_server -username $usr -Password $psd</div>
<div>$currentPswd = "
$newPswd = ""
$includeClusters = "","","","",""
$excludeServers = "."</div>
<div>Set-PowerCLIConfiguration -DefaultVIServerMode Multiple -Confirm:$false -DisplayDeprecationWarnings:$false -InvalidCertificateAction Ignore | Out-Null</div>

$includeClusters | %{

get-cluster $_ | Get-VMHost | where{$excludeServers -notcontains $_.Name.Split('.')[0]} | %{

Connect-VIServer -Server $_.Name -User root -Password $currentPswd -Verbose:$false | Out-Null
Set-VMHostAccount -Server  $_.Name -UserAccount root -Password $newPswd -Confirm:$false | Out-Null
echo "Root password of $_.Name is changed now"
Disconnect-VIServer -Server $_.Name -Confirm:$false


Leave a Comment

Your email address will not be published. Required fields are marked *