LucD. This worked flawlessly.
Here is an example set of code.
$vmName = "NRFVORION1"
$tgtDatastore = "ISCSIOBRSERVER"
$tgtCluster = "GD SVRM"
$tgtPool = "Resources"
Set-PowerCLIConfiguration -DefaultVIServerMode single -Confirm:$false
Connect-VIServer -Server 10.40.30.242 -User "administrator@vsphere.local" -Password "mypwhere"
$clus1 = Get-Cluster -Name $tgtCluster
$vm = Get-VM -Name $vmName
$ds = Get-Datastore -Name $tgtDatastore -RelatedObject $clus1
$esx = Get-Cluster -Name $tgtCluster | Get-VMHost | Get-Random
$rp = Get-ResourcePool -Name $tgtPool -Location $tgtCluster
$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")
Disconnect-VIServer -Server * -Force -Confirm:$false
One thing i noted was some devices do not move with say serial devices or printers hooked up.
I get error
Exception calling "RelocateVM" with "2" argument(s): "Currently connected
device 'Serial port 1' uses backing '/dev/char/serial/uart0', which is not
accessible."
At C:\sms\movevm.ps1:20 char:1
+ $vm.ExtensionData.RelocateVM($spec,"defaultPriority")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
There is a uart0 on the other server. I am trying to remove the port and readd it. If you have an example how to fix that. I would greatly appreciate your expert knowledge. :-)