param( [string] $esxhost,${newrootpasswd},$whatif=1,$showpasswd=0) $ErrorActionPreference = "SilentlyContinue" $WarningPreference = "SilentlyContinue" if (!$esxhost){Write-Host -ForegroundColor Red "no host input";break} # Password list ("" for *blank*) ${passwds} = "password","vmware","esxi","","0123456789" foreach ($passwd in $passwds){ $conex = Connect-VIServer -Server $esxhost -User root -Password $passwd -ErrorAction SilentlyContinue -WarningAction 0 if ($conex.IsConnected -eq "True") {break} } if (!$conex.IsConnected -eq "True"){ Write-Host $esxhost -NoNewline Write-Host " " -NoNewline Write-Host -ForegroundColor Red "Bad Password !" } else{ Write-Host $conex.Name -NoNewline Write-Host " " -NoNewline if ($passwd -eq $newrootpasswd){ Write-Host "ROOT PASSWORD == !" -BackgroundColor yellow -ForegroundColor black } else{ if ($whatif -eq "0"){ $setpasswd = Get-VMHostAccount -User "root"|Set-VMHostAccount -Password $newrootpasswd if ($setpasswd.Id -eq "root"){Write-Host "ROOT PASSWORD CHANGED !" -BackgroundColor green -ForegroundColor black} else {Write-Host "Set-VMHostAccount ERROR !" -BackgroundColor red -ForegroundColor black} } elseif ($whatif -eq "1" -and $showpasswd -eq "0"){ Write-Host "ROOT PASSWORD NOT CHANGED !" -BackgroundColor red -ForegroundColor black } elseif ($whatif -eq "1" -and $showpasswd -eq "1"){ Write-Host "ROOT PASSWORD = $passwd" -BackgroundColor Cyan -ForegroundColor black } } Disconnect-VIServer -Server $esxhost -Confirm:$false }