Hi,
I have quite specific requirements regarding host upgrade, so I’m writing a script which is roughly doing:
Upgrade ESXi
if (finished) {Start Firmware upgrade }
I need to know when ESXi upgrade is finished in order to start firmware upgrade. If reboot is needed whole operation might take ~20 -30 min
Wait-task wasn’t helpful because it time our after some time. So I wrote my own version of Wait-Task, but sometimes it “get stuck” when server is rebooted.
I can see in vCenter that server is back online, but when I check task status it’s still “Running” with 26%, when I press Enter on console with my script, task state is refreshed and it change to 100%, then script continue.
Do you have any idea how to fix it? Any help would be appreciated
Function WaitTask( $TaskID, [int]$Interval=5 ){
$Task = Get-task -id $TaskID
if($Task){
do{
$Task = Get-Task -Id $TaskID
$TaskName = $Task.Name
$TaskProgres = $Task.PercentComplete
$TaskState=$Task.State
$Text = "Task: $TaskName, State: $TaskState, Progress: $TaskProgres"
write-host -f blue $Text
Write-Log -Str $Text -Log $LogFile
sleep $Interval
}
until( ($TaskState -eq "Success") -or ($TaskState -eq "Error") )
return $TaskState
}else{
Write-host "TaskID is null"
}
}
$MyTask = Remediate-Inventory -Entity $EsxHost -Baseline $BaseLine -ClusterDisableHighAvailability:$true -Confirm:$false -RunAsync
$TaskState = WaitTask -TaskID $MyTask.ID -Interval 15
This is how the task status lok before I press the enter.
Name State % Complete Start Time Finish Time
---- ----- ---------- ---------- -----------
Remediate entity Running 26 05:48:20
ReconfigureComputeResource_... Success 100 05:48:21 05:48:21
InstallHostPatchV2_Task Success 100 05:48:41 05:48:47
CheckHostPatch_Task Success 100 05:48:47 05:48:47
RebootHost_Task Success 100 05:48:47 05:48:47
I have seen this before, the Remediate task status never gets updated, even after the ESXi node reboot.
It's as if the vCenter that manages the Task object looses track.
I tend to check for the ESXi node to come back online, and then, or check the new build of the ESXi node or check the events for the ESXi node or just do a new Scan of the ESXi node to check if the patches were applied.
It also helps if you Stage the patches before the Remediate, that considerably lowers the time of the Remediate (most of the time).
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference