VMware Cloud Community
Pilu1978
Enthusiast
Enthusiast
Jump to solution

Update-Tools : Operation is not valid due to the current state of the objec

Hi,


I have wriitten the following script to update VMTools on my Windows VM's. The script is running fine but it is throwing the following error for each and every VM. However it is successfully updating the VMTools on the VM.

17/11/2019 05:11:05 Update-Tools Operation is not valid due to the current state of the object.

$report = @()

if($VM.ExtensionData.Guest.ToolsVersionStatus -eq "guestToolsNeedUpgrade"){

Write-Host "Updating VMware tools on $($VM)" -ForegroundColor Green

Try{

Update-Tools $VM -ErrorAction Stop -RunAsync

$vmobj = "" | Select VM, Status

$vmobj.VM = $VM.name

$vmobj.Status = "VMTools installed successfully"

$report += $vmobj

}

Catch{

$vmobj = "" | Select VM, Status

$vmobj.VM = $VM.name

$vmobj.Status = $_.Exception.Message

$report += $vmobj

}

}

$report | Export-csv C:\temp\VMTools-Upgrade-Status.csv -notypeinformation.

I found some workaround mentioned here https://serverfault.com/questions/654415/powercli-move-vm-returns-failure-but-vm-stil... but not sure how to incorporate the same in my script or is there any other way to resolve it.

Please help.

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

I'm not too sure that the article you referenced is similar to what you are seeing.
The problem in the article is related to waiting for an async task.
And like the last entry in that article correctly states, a Task object does not refresh automatically.

Can you try your script, on a limited set of VMs, without the RunAsync switch?
And check if the error comes again for each VM.

It could also be useful to have a look in the vpxd log to find any additional information on why the error happens.


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

I'm not too sure that the article you referenced is similar to what you are seeing.
The problem in the article is related to waiting for an async task.
And like the last entry in that article correctly states, a Task object does not refresh automatically.

Can you try your script, on a limited set of VMs, without the RunAsync switch?
And check if the error comes again for each VM.

It could also be useful to have a look in the vpxd log to find any additional information on why the error happens.


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

0 Kudos
Pilu1978
Enthusiast
Enthusiast
Jump to solution

Thanks for reply.

Yes the script is running fine for limited number of VM's.

0 Kudos