-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathesxi_password_batch_update.ps1
31 lines (26 loc) · 1.04 KB
/
esxi_password_batch_update.ps1
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
# Connect to each ESXi host and set uniform password
# Password is not stored in any secure location
param (
[Parameter(Mandatory=$true)][string]$vcenter,
[Parameter(Mandatory=$true)][string]$currentpwd,
[Parameter(Mandatory=$true)][string]$newpwd
)
write-output "VCenter Server: $vcenter"
# Connect to vCenter or ESXi Host and enumerate hosts to be updated
Connect-VIServer $vcenter
$hosts = @()
Get-VMHost | sort | Get-View | Where {$_.Summary.Config.Product.Name -match "i"} | % { $hosts+= $_.Name }
Disconnect-VIServer -confirm:$false
foreach ($vmhost in $hosts) {
write-host "Connecting to $vmhost..."
Connect-VIserver -server $vmhost -user root -password "$currentpwd"
write-host "Changing root password on $vmhost..."
Set-VMHostAccount -UserAccount root -password "$newpwd"
if($?) {
Write-Output "Root password was updated on ESXi host - $vmhost to $newpwd"
}
else {
Write-Output "Error: Root password was *not* changed on the ESXi host - $vmhost"
}
Disconnect-VIServer -confirm:$false
}