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.
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
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
Thanks for reply.
Yes the script is running fine for limited number of VM's.