Hi All,
Is there a way to change all of my ESXi passwords from vCenter, the conditions ares
1.i have to run powercli connect vCenter
2. Show the new password from source file
You will need to have the password for the root account on the ESXi nodes.
Then you could do something like this (I assume the password is, and will be the same, on all ESXi nodes).
$user = 'root'
$pswd = 'VMware1!'
$newPswd = 'VMware2!'
$esxServers = Get-VMHost
foreach($esx in $esxServers){
$srv = Connect-VIServer -Server $esx.Name -User $user -Password $pswd 4> $null
if($srv){
Set-VMHostAccount -UserAccount $user -Password $newPswd -Server $srv -Confirm:$false
Disconnect-VIServer -Server $esx.Name -Confirm:$false
}
else{
Write-Host "Logon failed $($esx.Name)"
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you LucD for help always.
But the issue is , i dont have existing root password (old Infra)
new password for the host should not be unique, i will have to show them via txt or excel format,
script should pick new password from that file.
Picking the new password from a file is not really a problem.
But if you don't know the current password, I'm afraid you're stuck.
You can either reinstall ESXi or use an unsupported method to reset the root password (like for example the one in How to Reset the ESXi Root Password)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
I came across this link , which says we can change root password via vCenter. But it is bit confusing at $VMHost.
https://www.linkedin.com/pulse/reset-esxi-root-password-through-vcenter-esxcli-method-buschhaus/
And are your ESXi nodes 6.* ?
Btw, the content of $VMHost is just the output of Get-VMHost (while connected to a vCenter).
When the ESXi nodes are pre-6.* and you have HostProfiles, you could also try my function from Change The Root Password In Hosts And Host Profiles
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
They are 5.5 versoin...
So i believe this above script wont work for them.
Do you have HostProfile?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Experts, on similar lines, is there any way the script will pic data from a csv & then modify the root password which is unique for each host?
VMHost OldPass NewPass
ESX1 abc abc1
ESX2 xyz xyz1
ESX3 pqr pqr1
=====================================
$esxServers = get-content "e:/sho/esxpass.csv"
foreach($esx in $esxServers){
$srv = Connect-VIServer -Server $esx.VMHost -User root -Password $esx.OldPass
if($srv)
{Set-VMHostAccount -UserAccount $user -Password $esx.OldPass -Server $srv -Confirm:$false
Disconnect-VIServer -Server $esx.VMHost -Confirm:$false}
Else {Write-Host "Logon failed $($esx.VMHost)"}}
=====================================
Something like this???
Or just use the Import-Csv cmdlet
ForEach-Object -Process {
$srv = Connect-VIServer -Server $_.VMHost -User root -Password $_.OldPass
if($srv){
Set-VMHostAccount -UserAccount $user -Password $_.NewPass -Server $srv -Confirm:$false
Disconnect-VIServer -Server $_.VMHost -Confirm:$false
}
else{
Write-Host "Logon failed $($esx.VMHost)"
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference