Frequently Asked Questions
Change all ESX root passwords
Another great script from Arnim van Lieshout.
With this script you can change all ESX root passwords at once:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | # # This script changes the root password on all ESX hosts in the esxservers.txt textfile # # Add VI-toolkit # Add-PSsnapin VMware.VimAutomation.Core Initialize-VIToolkitEnvironment.ps1# Get old root credential $oldrootPassword = Read-Host “Enter old root password” -AsSecureString $oldrootCredential = new-object -typename System.Management.Automation.PSCredential -argumentlist “root”,$oldrootPassword # Get new root credential $newrootPassword = Read-Host “Enter new root password” -AsSecureString $newrootCredential = new-object -typename System.Management.Automation.PSCredential -argumentlist “root”,$newrootPassword $newrootPassword2 = Read-Host “Retype new root password” -AsSecureString $newrootCredential2 = new-object -typename System.Management.Automation.PSCredential -argumentlist “root”,$newrootPassword2 # Compare passwords If ($newrootCredential.GetNetworkCredential().Password -ceq $newrootCredential2.GetNetworkCredential().Password) { # Create new root account object $rootaccount = New-Object VMware.Vim.HostPosixAccountSpec $rootaccount.id = “root” $rootaccount.password = $newrootCredential.GetNetworkCredential().Password $rootaccount.shellAccess = “/bin/bash” # Get list of Host servers from textfile to change root password on Get-Content esxservers.txt | %{ Connect-VIServer $_ -User root -Password $oldrootCredential.GetNetworkCredential().Password -ErrorAction SilentlyContinue -ErrorVariable ConnectError | Out-Null If ($ConnectError -ne $Null) { Write-Host “ERROR: Failed to connect to ESX server:” $_ } Else { $si = Get-View ServiceInstance $acctMgr = Get-View -Id $si.content.accountManager $acctMgr.UpdateUser($rootaccount) Write-Host “Root password successfully changed on” $_ Disconnect-VIServer -Confirm:$False | Out-Null } } } Else { Write-Host “ERROR: New root passwords do not match. Exiting…” } |
Example esxservers.txt:
1 2 3 4 | esx001.yourdomain.local esx002.yourdomain.local esx003.yourdomain.local esx004.yourdomain.local |
Download: Change root Password on ESX (121)
