I got the below script but after restarting vpxa agent, I think I lose connection and unable to conitnue and set the host back to connected. any idea?
# Put host in Maintenance mode and apply host profile
set-vmhost -vmhost $vmhost -state "Maintenance" -confirm:$false
Invoke-vmhostprofile $vmhost -confirm:$false | Test-VMhostprofilecompliance
# Restart watchdog service
#$esxhosts = get-vmhost -name (get-content esxhosts.txt)
#foreach ($vmhost in $esxhosts){}
$esxcli = get-esxcli -vmhost $vmhost -V2
$esxcli.hardware.ipmi.sel.clear.Invoke()
$esxcli.system.wbem.set.Invoke(@{enable=$false})
$esxcli.system.wbem.set.Invoke(@{enable=$true})
get-vmhostservice -vmhost $vmhost | ? {$_.Running -eq "True"} | restart-vmhostservice -confirm:$false -ErrorAction Silentlycontinue
set-vmhost -vmhost $vmhost -state connected <-------
Can't you use a While-loop and wait till the state of the ESXi node shows 'maintenance' again?
Restart-VMHostService -Confirm:$false -ErrorAction Silentlycontinue
$esx = Get-VMHost -Name $vmhost -ErrorAction SilentlyContinue
while($esx.State -ne 'maintenance'){
sleep 5
$esx = Get-VMHost -Name $vmhost -ErrorAction SilentlyContinue
}
set-vmhost -vmhost $vmhost -state connected
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Can't you use a While-loop and wait till the state of the ESXi node shows 'maintenance' again?
Restart-VMHostService -Confirm:$false -ErrorAction Silentlycontinue
$esx = Get-VMHost -Name $vmhost -ErrorAction SilentlyContinue
while($esx.State -ne 'maintenance'){
sleep 5
$esx = Get-VMHost -Name $vmhost -ErrorAction SilentlyContinue
}
set-vmhost -vmhost $vmhost -state connected
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks. That works