VMware PowerCLI

The Best User Interface for your VMware Datacenter!

Operation is not valid due to the current state of the object

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.

  • Luc FULLENWARTH
  • Jul 25 2019
  • Looking for Feedback
  • Attach files
  • Luc FULLENWARTH commented
    February 13, 2020 20:05

    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.

  • Luc FULLENWARTH commented
    February 13, 2020 16:04

    I have now systematically this one which is very hindering because you cannot pipe it to the New-ScsiController cmdlet:

    PS> New-HardDisk -VM $vm -CapacityGB 1 -Verbose
    VERBOSE: Performing operation 'New hard disk.' on Computer1.
    VERBOSE: 13/02/2020 16:52:48 New-HardDisk Finished execution
    New-HardDisk : 13/02/2020 16:52:48 New-HardDisk Operation is not valid due to the current state of the object.
    At line:1 char:1
    + New-HardDisk -VM $vm -CapacityGB 1 -Verbose
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [New-HardDisk], VimException
    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.NewHardDisk
  • Jason Robinson commented
    January 09, 2020 21:52

    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.

  • Brad Calvert commented
    September 27, 2019 00:39

    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.