VMware Cloud Community
tdubb123
Expert
Expert
Jump to solution

restarting vpxa agent and then losing connection

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?

param($vmhost)

# 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 <-------

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Can't you use a While-loop and wait till the state of the ESXi node shows 'maintenance' again?

Get-VMHostService -VMHost $vmhost | Where {$_.Running -eq "True"} |

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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

Can't you use a While-loop and wait till the state of the ESXi node shows 'maintenance' again?

Get-VMHostService -VMHost $vmhost | Where {$_.Running -eq "True"} |

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

0 Kudos
tdubb123
Expert
Expert
Jump to solution

Thanks. That works

0 Kudos