VMware Cloud Community
tdubb123
Expert
Expert

powercli remediate hosts one ast a time

I am trying this script but it is not waiting for the host to be paotched and come back online before putting the second host into maintenance mode.

$baseline = get-baseline -server vc -name "6.5 dynamic"

$vmhosts = get-vmhost (get-content esxhosts.txt)

foreach ($vmhost in $vmhosts){

get-vmhost -name $vmhost | set-vmhost -state maintenance -confirm:$false

scan-inventory -entity $vmhost

$baseline | remediate-inventory -entity $vmhost -confirm:$false -erroraction silentlycontinue

}

any idea why it is putting the second host into maintenance mode before waiting for the 1st host to come back online?

thanks

0 Kudos
4 Replies
tdubb123
Expert
Expert

also it quits after remediating 2 hosts

0 Kudos
LucD
Leadership
Leadership

You will have to build your own wait-loop after each ESXi node's Remediate.
Best is to wait till the ESXi node is back, and fully operational in the cluster, just a test for powered on is not enough most of the time.

Waiting till the vpxa service is running again would be a good test.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
tdubb123
Expert
Expert

I am trying this but getting error

$baseline = get-baseline -server vc -name "6.5 dynamic"

$vmhosts = get-vmhost (get-content esxhosts.txt)

foreach ($vmhost in $vmhosts){

$baseline | attach-baseline -entity $vmhost -confirm:$false

get-vmhost -name $vmhost | set-vmhost -state maintenance -confirm:$false

scan-inventory -entity $vmhost

$task = $baseline | remediate-inventory -entity $vmhost -confirm:$false -erroraction silentlycontinue -runasync

while ($task.percentcomplete -ne 100) {

start-sleep 10

$task = get-task -id $task.id

}

}

Screen Shot 2018-11-29 at 7.28.35 AM.png

0 Kudos
LucD
Leadership
Leadership

Did you stop/start your PowerShell/PowerCLI session before the test?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos