We have esxi hosts with different root passwords spread across. Need to validate at least 3 passwords on each of the host and log the status as we validate.
Trying something like this but the code could validate only 2 passwords. Also, looking for a better code to validate n (2,3,4 so on.) number of passwords possibly per host.
Appreciate your inputs.
(I understand this is not the secure way to pass the password to variables, i will handle it later though)
Import-Module VMware.VimAutomation.Core
$username = root
$password1 = PASS1
$password2 = PASS2
$password3 = PASS3
$hstlist = Get-Clipboard
$Logfile = “E:ScriptsAuthentication-CheckScriptLog-Host-$Date.log”
Function LogWrite
{
Param ([string]$logstring)
Add-content $Logfile -value $logstring
}
foreach ($vmhost in $hstlist){
$global:DefaultVIServer = $null
$global:DefaultVIServers = $null
$Conn = Connect-VIServer -Server $vmhost -User $username -Password $password1
if ($Conn) {
LogWrite “Authenticated host $vmhost using password 1”
}
else{
Connect-VIServer $vmhost -User $username -Password $password2
LogWrite “Authenticated host $vmhost using password 2”
}
}