When I try this code in 6.0 I just get multiple errors.
$vmName = "MYVM"
$tgtDatastore = "TestSAN"
$tgtCluster = "GD SVRM"
$tgtPool = "Resources" - I notice i cannot define a resource pool for this DC.
$vm = Get-VM -Name $vmName
$ds = Get-Datastore -Name $tgtDatastore
$esx = Get-Cluster -Name $tgtCluster | Get-VMHost | Get-Random
$rp = Get-ResourcePool -Name $tgtPool
$spec = New-Object VMware.Vim.VirtualMachineRelocateSpec
$spec.Datastore = $ds.ExtensionData.MoRef
$spec.Host = $esx.ExtensionData.MoRef
$spec.Pool = $rp.ExtensionData.MoRef
$vm.ExtensionData.RelocateVM($spec,"defaultPriority")
Exception setting "Datastore": "Cannot convert the "System.Object[]" value of
type "System.Object[]" to type "VMware.Vim.ManagedObjectReference"."
At C:\movevm.ps1:12 char:1
+ $spec.Datastore = $ds.ExtensionData.MoRef
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], SetValueInvocationExceptio
n
+ FullyQualifiedErrorId : ExceptionWhenSetting
Exception setting "Pool": "Cannot convert the "System.Object[]" value of type
"System.Object[]" to type "VMware.Vim.ManagedObjectReference"."
At C:\movevm.ps1:14 char:1
+ $spec.Pool = $rp.ExtensionData.MoRef
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], SetValueInvocationExceptio
n
+ FullyQualifiedErrorId : ExceptionWhenSetting
Exception calling "RelocateVM" with "2" argument(s): "A specified parameter
was not correct: spec.location.datastore"
At C:\movevm.ps1:15 char:1
+ $vm.ExtensionData.RelocateVM($spec,"defaultPriority")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
Any help would be appreciated.