VMware Cloud Community
JLogan2016
Enthusiast
Enthusiast

Migration of VMs from one vCenter to another

I am currently working on a script for a customer who is splitting their Prod and Non-Prod workload between two unlinked vCenter instances. The only thing I have is the datastores for Prod (I1 datastores) mapped to the new Non-Prod environment (I2). I have done this kind of migration in the past, and had a script (admittedly 5.5) I have used elsewhere that always worked well. The basic workflow is:

  • Do a Get-VM and collect VM Name, PortGroup, IP Address, Datastore
  • Power Down in old vCenter
  • Unregister from old vCenter
  • Register in new vCenter, in one of two folders based on VM name
  • Set VLAN accordingly
  • Power On VM, answer "Copy/Move" question
  • Confirm connectivity and that IP address matches
  • Start a vMotion from old datastore to new datastore cluster, based on VM name

I turned the old script into a function to allow easy testing both ways directions with test machines - Prod to Non-Prod and then back again. From the new Non-Prod (6.7) to the Prod (6.5), everything works just fine. But from Prod to Non-Prod, the startup question never gets answered, and the power up hangs. I am using the following:

            $vm |

                Get-VMQuestion |

                    Set-VMQuestion -Option “button.uuid.movedTheVM” -Confirm:$false

which is what I have always done. I have been searching online, but did not come across anything different for 6.7 for the Set-VMQuestion; is there some obvious reason why it would work in the older environment but not the newer.?

Reply
0 Kudos
5 Replies
LucD
Leadership
Leadership

Are you sure you are running this on the correct vCenter?

Perhaps add the Server parameter to make sure.

Btw, just tested this, and it works for me.


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

Reply
0 Kudos
JLogan2016
Enthusiast
Enthusiast

I do specify -Server in the Get-VM (not shown). I will try it in this pipe as well.

Reply
0 Kudos
JLogan2016
Enthusiast
Enthusiast

So I have tried both this way:

    $VMList |

        % {

           

            $vm = Get-VM -Name $_.Parent -Server $Destination_vCenter

           

            $vm |

                Get-VMQuestion -Server $Destination_vCenter |

                    Set-VMQuestion -Option “button.uuid.movedTheVM” -Confirm:$false

            Start-VM $vm.Name

          }

And this way:

$vm = Get-VM -Name $_.Parent -Server $Destination_vCenter

Start-VM $vm.Name -Server $Destination_vCenter

Sleep 10

$vm | Get-VMQuestion -Server $Destination_vCenter | Set-VMQuestion -Option “button.uuid.movedTheVM” -Confirm:$false

But no joy either way. And only when moving to the 6.7 environment. Moving from the 6.7 back to 6.5 they start up every single time.

Reply
0 Kudos
LucD
Leadership
Leadership

A wild guess, did you already try with the DefaultOption switch instead of the Option parameter?
Also, if you use the Option parameter, did you try the Copy and the Move option?


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

Reply
0 Kudos
JLogan2016
Enthusiast
Enthusiast

I hadn't tried setting it to -DefaultOption only because when I looked at the VMQuestion the default was "I Copied It", and I need to maintain the MAC address through the move. In the end, the code below seems to work, suppressing the error message to the console about there being a pending question, and then answering it with the moved option. Kind of kludgy but it works. Thanks for the help as always.

    $VMList |

        % {

           

            $vm = Get-VM -Name $_.Parent -Server $Destination_vCenter

           

            Start-VM $vm.Name -ErrorAction SilentlyContinue | Out-Null

            Start-Sleep 5

            $vm |

                Get-VMQuestion -Server $Destination_vCenter |

                    Set-VMQuestion -Option “button.uuid.movedTheVM” -Confirm:$false

          }

Reply
0 Kudos