VMware Cloud Community
jackchentoronto
Enthusiast
Enthusiast
Jump to solution

Move-VM doesn't work against new VCSA 6.7 instance

Hi,

I am trying to write a PowerCli script to move a VM to a chosen folder/resource pool. I found "move-vm" is working fine against a old vCenter 6.0 instance, but doesn't work with new 6.7 VCSA for resource pool.

My code is like :

C:\>$rp=get-resourcepool "a-unique-resource-pool" -location "my-cluster"

C:\>$folder=get-Folder "a-unique-folder"

C:\>$vm=get-vm "one-vm-name"

C:\>move-vm -vm $vm -InventoryLocation $folder

### all work as expected.

C:\>move-vm -vm $vm -destination $rp

The above code works fine for vCenter 6.0, but failed on VCSA 6.7 with following error:

move-vm : 1/30/2019 5:08:43 PM  Move-VM         Object reference not set to an instance of an object.

At line:1 char:1

+ move-vm -vm $vm -destination $rp

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Move-VM], VimException

    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.MoveVM

I have tried to download the "PowerCLI 6.5 Release 1" from vmware website or directly install VMware.PowerCLI by "install-module VMware.PowerCLI", both have same problem.

"Get-InstalledModule" shows:

6.7.0.1... VMware.DeployAutomation             PSGallery            This Windows PowerShell module contains PowerCLI Auto Deploy cmdlets.

6.7.0.1... VMware.ImageBuilder                 PSGallery            This Windows PowerShell module contains PowerCLI ImageBuilder cmdlets.

11.1.0.... VMware.PowerCLI                     PSGallery            This Windows PowerShell module contains VMware.PowerCLI

6.7.0.1... VMware.Vim                          PSGallery            This Windows PowerShell module contains PowerCLI Vim.

11.0.0.... VMware.VimAutomation.Cis.Core       PSGallery            This Windows PowerShell module contains PowerCLI Cloud Infrastructure Suite cmdlets.

11.0.0.... VMware.VimAutomation.Cloud          PSGallery            This Windows PowerShell module contains PowerCLI Cloud cmdlets.

11.0.0.... VMware.VimAutomation.Common         PSGallery            This Windows PowerShell module contains functionality required by multiple PowerCLI modules.

11.0.0.... VMware.VimAutomation.Core           PSGallery            This Windows PowerShell module contains Windows PowerShell cmdlets for managing vSphere.

7.6.0.1... VMware.VimAutomation.HorizonView    PSGallery            This Windows PowerShell module contains Connect/Disconnect cmdlets for View API service.

10.0.0.... VMware.VimAutomation.License        PSGallery            This Windows PowerShell module contains PowerCLI cmdlets for managing VMware product licenses.

11.0.0.... VMware.VimAutomation.Nsxt           PSGallery            This Windows PowerShell module contains PowerCLI NSXT cmdlets.

11.0.0.... VMware.VimAutomation.Sdk            PSGallery            This Windows PowerShell module contains PowerCLI Sdk.

11.0.0.... VMware.VimAutomation.Security       PSGallery            This Windows PowerShell module contains PowerCLI security management cmdlets.

11.1.0.... VMware.VimAutomation.Srm            PSGallery            This Windows PowerShell module contains PowerCLI SRM cmdlets.

11.1.0.... VMware.VimAutomation.Storage        PSGallery            This Windows PowerShell module contains PowerCLI storage management cmdlets.

1.3.0.0    VMware.VimAutomation.StorageUtility PSGallery            This Windows PowerShell module contains utility scripts for storage.

11.0.0.... VMware.VimAutomation.Vds            PSGallery            This Windows PowerShell module contains PowerCLI VDS cmdlets.

11.0.0.... VMware.VimAutomation.Vmc            PSGallery            This Windows PowerShell module contains PowerCLI VMC cmdlets.

10.0.0.... VMware.VimAutomation.vROps          PSGallery            This Windows PowerShell module contains PowerCLI vROps cmdlets.

6.5.1.7... VMware.VumAutomation                PSGallery            This Windows PowerShell module contains PowerCLI VUM cmdlets.

The latest document I can find is https://code.vmware.com/doc/preview?id=6330#/doc/Move-VM.html

Anybody know how I can use PowerCli to move a VM to a resourcepool against VCSA 6.7?

Thanks,

Jack

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

There are a few known issues with Move-VM in PowerCLI 11.1.0.

Currently the only way around it is to use the vSphere API method.

$vmName = 'MyVM'

$rpName = 'MyRP'


$vm = Get-VM -Name $vmName

$rp = Get-ResourcePool -Name $rpName


$spec = New-Object VMware.Vim.VirtualMachineRelocateSpec

$spec.Pool = $rp.ExtensionData.MoRef


$vm.ExtensionData.RelocateVM($spec, [VMware.Vim.VirtualMachineMovePriority]::defaultPriority)


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

View solution in original post

4 Replies
jackchentoronto
Enthusiast
Enthusiast
Jump to solution

Anybody can confirm "move-vm -vm $vm  -destination $resourcepool" works with VCSA 6.7?  the resource pool and the VM are on same cluster (with only one ESXi host for testing).

I found on 6.7 "move-vm -vm $vm  -destination $cluster" also doesn't work for me, but ""move-vm -vm $vm  -destination $the_vmhost" is working.

Online Documentation - Cmdlet Reference - VMware {code} has:

" If the virtual machine is outside the non-DRS cluster, you need to specify a virtual machine host in that cluster as destination."

But my VM is inside the cluster ( with DRS enabled, but just one host).

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

There are a few known issues with Move-VM in PowerCLI 11.1.0.

Currently the only way around it is to use the vSphere API method.

$vmName = 'MyVM'

$rpName = 'MyRP'


$vm = Get-VM -Name $vmName

$rp = Get-ResourcePool -Name $rpName


$spec = New-Object VMware.Vim.VirtualMachineRelocateSpec

$spec.Pool = $rp.ExtensionData.MoRef


$vm.ExtensionData.RelocateVM($spec, [VMware.Vim.VirtualMachineMovePriority]::defaultPriority)


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

jackchentoronto
Enthusiast
Enthusiast
Jump to solution

Nice! will try it and accept this as answer.

Reply
0 Kudos
jackchentoronto
Enthusiast
Enthusiast
Jump to solution

Worked like charm!

Reply
0 Kudos