VMware Cloud Community
tdubb123
Expert
Expert

Write-Progress : Cannot validate argument on parameter 'PercentComplete'.

Not sure why this does not get out of the while loop

$esxhost = read-host "Enter the host to upgrade"

$poweredonvms = get-vmhost -name $esxhost | get-vm | ?{$_.powerstate -eq "Poweredon"}

$baseline = get-baseline -server vcenter -Name "DELL_esxi_7.0U3C_Upgrade"
 
#shutdown all powered on vms 
$poweredonVms | shutdown-vmguest -confirm:$false
start-sleep 60
   
    set-vmhost -VMHost $esxhost -State Maintenance -Confirm:$false
 
    $baseline | Attach-Baseline -entity $esxhost -Confirm:$falsw\e
   
   
    $updatetask = $baseline | Remediate-Inventory -Entity $esxhost -Confirm:$false
   
     
   
    # Wait for patch task to complete
   
    while ($UpdateTask.PercentComplete -ne 100)
   
    {
   
    Write-Progress -Activity "Waiting for $esxhost to finish patch installation" -PercentComplete $UpdateTask.PercentComplete
   
    Start-Sleep -seconds 10
   
    $UpdateTask = Get-Task -id $UpdateTask.id
   
    }
   
    set-vmhost -VMHost $esxhost -State Connected -Confirm:$false
 
$poweredonVMs = get-vm -vmhost $esxhost | start-vm -confirm:$false
Reply
0 Kudos
5 Replies
tdubb123
Expert
Expert

also in the 60s, some vm are not shutdown yet and the task proceeded to remediate. how do i check and see if all vms are powered off

Reply
0 Kudos
LucD
Leadership
Leadership

To wait for all VMs to be powered off, you could do

#shutdown all powered on vms 
$poweredonVms | Shutdown-VMGuest -Confirm:$false
While ((Get-VM -Name ($poweredonvms.Name).PowerState -contains 'poweredon' )){
  Start-Sleep -Seconds 5
}

Did you check what is actually in $updatetask?
Especially the Id and PercentComplete properties.
Does the Get-Task in the loop actually return a Task object?



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

Reply
0 Kudos
tdubb123
Expert
Expert

i think I am not seeing a task

 

Write-Progress : Cannot validate argument on parameter 'PercentComplete'. The argument is null, empty, or an element of the argument collection contains a null
value. Supply a collection that does not contain any null values and then try the command again.
upgrade_esxi.ps1:30 char:99
+ ... nish patch installation" -PercentComplete $UpdateTask.PercentComplete
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Write-Progress], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.WriteProgressCommand

Get-Task : Cannot validate argument on parameter 'Id'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command
again.
upgrade_esxi.ps1:34 char:32
+ $UpdateTask = Get-Task -id $UpdateTask.id
+ ~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-Task], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.Common.Commands.Cmdlets.GetTask

Reply
0 Kudos
tdubb123
Expert
Expert

also seeing this while remediating host

 

 


RemediateTask
percent complete: 44
[ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo ]

Id : HostSystem-host-27940

DatastoreIdList : {Datastore-datastore-27941}

Remediate-Inventory : 8/7/2022 10:56:13 AM Update-Entity The underlying connection was closed: A connection that was expected to be kept alive was closed by
the server.
upgrade_esxi.ps1:22 char:31
+ ... sk = $baseline | Remediate-Inventory -Entity $esxhost -Confirm:$false
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Update-Entity], ViError
+ FullyQualifiedErrorId : Client20_QueryServiceImpl_WaitForUpdates_ViError,VMware.VumAutomation.Commands.RemediateInventory

Reply
0 Kudos
LucD
Leadership
Leadership

Those are other issues with your script as far as I can tell.
They are not related to the snippet to make sure all VMs are powered off before proceeding


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

Reply
0 Kudos