glennbezanson
Contributor
Contributor

Datacenter migration script from standard to distributed portgroups with the same name

Hello friends,

I'm currently working on trying to migrating virtual machines to a new datacenter. Networks are identical (stretched) in both datacenters but we have to do a svmotion to move between them.

I've cobbled together a powercli script from various sources that basically imports today selected VM's through a CSV, then cycles through it while spawning new Move-VM's once the running sessions is under a predefined threshold. But, I'm running into issues with migrating systems that are on standard switches over to distributed switched. Port group names are all identical, so I figured I could just use the name element in the destinations port group. It seems to have worked ok on system with a single nic, but I started running into issues with multiple nics.

I ran across an article by Kyle Ruddy - Spotlight on the Move-VM Cmdlet including PowerCLI 6.5 Enhancements that showed you can pipe arrays. I also found an article that LucD was helping on which was more recent, move-vm script placing port groups on wrong adapters for VMs with multiple nics but have still been unable to resolve my issues.

Snipped of code for picking the network adapter:

      # Pick target port group based on source port group name. Cycle through for multiple network adapters

      $NetworkAdapter = Get-NetworkAdapter -vm $vm

      $targetpg = @()

      $NetworkAdapter.count | foreach-object {

      $targetpg += Get-VDPortgroup -name $NetworkAdapter.networkname

   }

Move VM command:

Move-VM -VM $vm `

      -Destination $DestinationHost `

      -NetworkAdapter $NetworkAdapter `

      -PortGroup $targetpg  `

      -Datastore (Get-DatastoreCluster -Name $DestinationDatastore | Get-Datastore | Sort-Object -Property FreeSpaceGB -Descending | Select -First 1) `

      -RunAsync -Confirm:$false

But when I am currently getting the following error:

Move-VM : 10/31/2020 2:12:56 PM Move-VM A specified parameter was not correct: RelocateSpec

At line:1 char:1

+ Move-VM -VM $vm `

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

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

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

I tried using the sdk method but never could get it to work with standard switch moves. 

Any insight or help would be much appreciated. Thanks!!

0 Kudos
4 Replies
LucD
Leadership
Leadership

Are these datacenters (old & new) in the same vCenter?

If you have VMs with multiple vNICs, are they all connected to the same portgroup?

The error message seems to indicate that the underlying API call (from MOve-VM) has an error in the spec.

Can you check what the vpxd log is saying for that error?

It might contain more information.

You can eventually change logging on the vCenter from Info to Debug temporarily.


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

0 Kudos
glennbezanson
Contributor
Contributor

Sorry, that's definitely some details I didn't mean to leave out.

  • Same vCenter.
  • Multiple vNICs are on different port groups.
  • Pulling logs, probably take a few to go through but I'll post back here.

Thanks!

0 Kudos
LucD
Leadership
Leadership

At my recent CodeConnect session, I showed a method to automate that interaction with the vpxd log.

See Vpxd_Verbose.ps1


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

0 Kudos
glennbezanson
Contributor
Contributor

Sorry, didn't mean to not reply. It was easier to just move the standard switch VM's to a distributed switch. I can replicate the issue I'm having in my lab though (which has a lot less log events). I'm going to reproduce the error then pull logs and see what I get from that. The script I'm working on ~I think~ is a pretty nice all around VM mover, so I'd like to get standard to distributed as part of the process. I'll keep you posted on what I find.

0 Kudos