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.
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.
Attachments Open full size
I have now systematically this one which is very hindering because you cannot pipe it to the New-ScsiController cmdlet:
Attachments Open full size
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.
Attachments Open full size
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.
Attachments Open full size