Many cmdlets are sometimes returning this error message:
Operation is not valid due to the current state of the object
This problem has been discussed and a workaround has been found here :
https://serverfault.com/questions/654415/powercli-move-vm-returns-failure-but-vm-still-moves
However, instead of a workaround with more code, it would be better to fix this erratic behavior.
It's a workaround, but I've read if you the add the
-runassync
to the the command line, it runs slower but doesn't give an error.Just noticed I have this issue with a lot of cmdlets on Windows 10 but not on Windows Server 2012 R2, though I use the latest version of the VMware.PowerCli module on both.
I have now systematically this one which is very hindering because you cannot pipe it to the New-ScsiController cmdlet:
I hit this error today with New-VM. Provisioning engine failed to deploy VM and received the 'operation is not valid due to the current state of object', then it deployed the next 10 VMs even though New-VM continued to error out with the same message. Not sure if this is a PowerCli bug or a PowerShell one.
I definitely have this problem, and at scale. Trying to perform some shared-nothing migrations of hundreds or ultimately thousands of VMs. Sometimes the PowerShell environments in to a state where this happens to every VM. The only solution is to close PowerShell and re-open, because even disconnecting and reconnecting from vCenter and re-starting the script does not help. Even then it is only a matter of time before it happens again. The main issue obviously being when the failure occurs, the script may queue dozens or hundreds of VMs up for moves in vCenter.