PowerCli: bulk change ESXi root passwords with vCenter

sometimes you have to change the root password for all ESXi hosts.
You can use the PowerCLI Set-VMHostAccount cmdlet. But this requires you to connect to each individual ESXi host, it cannot be run when connected to the vCenter server.

So, I’ve created a (rather small) script which changes the root passwords for all (or a subset) of the ESXi hosts, which are connected to a vCenter server.

$cred = Get-Credential -UserName "root" -message "Enter new ESXi root password"
$vmhosts = get-vmhost | Out-GridView -PassThru -Title "Select ESXi hosts for changing the root password"
Foreach ($vmhost in $vmhosts) {
    $esxcli = get-esxcli -vmhost $vmhost -v2 

This script request you to enter the new root password.
Then it request you to make a selection of ESXi hosts which from which the root password must be changed.
After you’ve pressed OK, a few moments (seconds) later, the root passwords have been changed for the selected ESXi hosts.

Please be aware that this script does not connect to the vCenter itself, it requires you to execute the connect-viserver cmdlet yourself.

Please leave a comment if you think this script is useful!

4 gedachtes over “PowerCli: bulk change ESXi root passwords with vCenter

  1. Get-EsxCli : A parameter cannot be found that matches parameter name ‘v2’.
    At U:\Nutanix\Esxi_host_swd_Chg.ps1:10 char:42
    + $esxcli = get-esxcli -vmhost $vmhost -v2
    + ~~~
    + CategoryInfo : InvalidArgument: (:) [Get-EsxCli], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetEsxCli

    You cannot call a method on a null-valued expression.
    At U:\Nutanix\Esxi_host_swd_Chg.ps1:11 char:5
    + $esxcli.system.account.set.Invoke(@{id=$cred.UserName;password=$cred.GetNetw …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull


Geef een reactie

Vul je gegevens in of klik op een icoon om in te loggen.

WordPress.com logo

Je reageert onder je WordPress.com account. Log uit /  Bijwerken )

Google photo

Je reageert onder je Google account. Log uit /  Bijwerken )


Je reageert onder je Twitter account. Log uit /  Bijwerken )

Facebook foto

Je reageert onder je Facebook account. Log uit /  Bijwerken )

Verbinden met %s