Chrisxxxx
Contributor
Contributor

Error with Move-VM: Operation is not valid due to the current state of the object.

Jump to solution

  I only started getting this after updating to PowerCLI v5.1.  My vCenter is still v5.0.  I've only seen this when moving VMs' to a datastore in a different datastore cluster.  The task submits to vCenter successfully and completes, but the Move-VM errors and returns control to the script or command line that ran it.

$> Move-VM -VM somevm -Datastore somedatastore -Confirm:$false
Move-VM : 11/13/2012 4:07:45 PM    Move-VM        Operation is not valid due to the current state of the object.
At line:1 char:1
+ Move-VM -VM somevm -Datastore somedatastore -Confirm:$false
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Move-VM], VimException
    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.MoveVM

I'm stumped.

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

Do you by any chance have a PowerShell v2 available somewhere where you can run the same script ?

Afaik there is no official PS v3 support yet in PowerCLI, although there are only a few minor gotchas known.

Just clutching at straws :smileygrin:


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

View solution in original post

0 Kudos
5 Replies
LucD
Leadership
Leadership

Are you by any chance running this from PowerGUI ?

If yes, you should upgrade your PowerGUI. See Re: Set-NetworkAdapter returning 'Operation is not valid due to the current state of the object'


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

0 Kudos
Chrisxxxx
Contributor
Contributor

  I did see that thread.  I'm running it from a straight shell.  The one that looks like the old DOS box.  Smiley Happy

  I'm starting to wonder if it's a problem with the default output formatter.  I have a function "Relocate-VM" that is a wrapper around "Move-VM -Datastore" with some checks.  When I run the function by itself on the command line I get the error.  I normally run it in a foreach loop and one svmotion happens at a time, but with the error causing the cmdlet to exit I could have dozens of svmotions submitted at once.  To avoid that I put in some extra stuff to throttle the svmotions and I didn't get the error.  I know other times when I've made a one-liner too complex the default formatting didn't work, so that's why I suspect the formatter or the format definition.  Below is the one-liner where I don't get the error (Get-mTask is my function):

$> import-csv .\servers.csv | select vm | % { Relocate-mVM -VM $_.VM; sleep 60; if ((Get-mTask | ? { ($_.finishtime -eq $null) -and ($_.descript
ion -match "relocate") } | measure).count -gt 2) { sleep 600 } }

  Some version info in case it helps.

$> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      3.0
WSManStackVersion              3.0
SerializationVersion           1.1.0.1
CLRVersion                     4.0.30319.17929
BuildVersion                   6.2.9200.16398
PSCompatibleVersions           {1.0, 2.0, 3.0}
PSRemotingProtocolVersion      2.2


[17:03:32] - [vcenter202] - [D:] BedQA_Cluster_Split
$> Get-PowerCLIVersion

PowerCLI Version
----------------
   VMware vSphere PowerCLI 5.1 Release 1 build 793510
---------------
Snapin Versions
---------------
   VMWare AutoDeploy PowerCLI Component 5.1 build 768137
   VMWare ImageBuilder PowerCLI Component 5.1 build 768137
   VMware vCloud Director PowerCLI Component 1.5 build 793505
   VMware License PowerCLI Component 5.1 build 669840
   VMware vSphere PowerCLI Component 5.1 build 793489

vCenter version is v5.0.0, build 623373

0 Kudos
LucD
Leadership
Leadership

Do you by any chance have a PowerShell v2 available somewhere where you can run the same script ?

Afaik there is no official PS v3 support yet in PowerCLI, although there are only a few minor gotchas known.

Just clutching at straws :smileygrin:


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

View solution in original post

0 Kudos
Chrisxxxx
Contributor
Contributor

Yep, works fine under PowerShell v2.  I didn't realize v3 wasn't supported for PowerCLI yet, that I was a beta tester.  Smiley Happy

$> $PSVersionTable

Name                           Value
----                           -----
CLRVersion                     2.0.50727.5456
BuildVersion                   6.1.7601.17514
PSVersion                      2.0
WSManStackVersion              2.0
PSCompatibleVersions           {1.0, 2.0}
SerializationVersion           1.1.0.1
PSRemotingProtocolVersion      2.1


[10:40:55] - [vcenter202] - [D:] Temp
$> Get-PowerCLIVersion

PowerCLI Version
----------------
   VMware vSphere PowerCLI 5.1 Release 1 build 793510
---------------
Snapin Versions
---------------
   VMWare AutoDeploy PowerCLI Component 5.1 build 768137
   VMWare ImageBuilder PowerCLI Component 5.1 build 768137
   VMware vCloud Director PowerCLI Component 1.5 build 793505
   VMware License PowerCLI Component 5.1 build 669840
   VMware vSphere PowerCLI Component 5.1 build 793489

0 Kudos
LucD
Leadership
Leadership

Nope, the Release Notes only specify PS v2.

Looks like you found a PS v3 "feature" in PowerCLI :smileygrin:


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

0 Kudos