If using your voice to create an HCX Mobility Group and initiate a migration to a VMware Cloud SDDC is not your thing, here is a more practical example using PowerCLI which includes HCX cmdlets that was introduced awhile back.
Here are the 12 configurable variables that you will need to update based on your own environment.
$VC_SERVER="vcsa.vmware.corp" $VC_USERNAME="*protected email*" $VC_PASSWORD="VMware1!" $HCX_SERVER="hcx.vmware.corp" $VSPHERE_TAG_CATEGORY="Cloud" $VSPHERE_TAG_NAME="VMC" # vMotion, Bulk, Cold, RAV, OsAssistedMigration $MIGRATION_TYPE="RAV" $TARGET_NETWORK_NAME="L2E_HOL-10-f58e483b" $TARGET_DATASTORE_NAME="WorkloadDatastore" $TARGET_RESOURCE_POOL_NAME="Compute-ResourcePool" $TARGET_VM_FOLDER_NAME="Workloads" $MOBILITY_GROUP_NAME="VMworld-2020-Demo"
Next, we will connect to both our vCenter Server and HCX Manager endpoint to retrieve the VM details required to construct our HCX Mobility Group:
Connect-VIServer -Server $VC_SERVER -User $VC_USERNAME -Password $VC_PASSWORD -Force | Out-Null
Connect-HCXServer -Server $HCX_SERVER -User $VC_USERNAME -Password $VC_PASSWORD | Out-Null
This is line describes how we are filtering out the list of VMs. In this example, we are using vSphere Tags BUT, you can certainly filtering on almost any attribute you desire. This is just one very specific example and you can update the filtering logic to other parameters to create the $vms array list.
$vms = (Get-TagAssignment -Category $VSPHERE_TAG_CATEGORY | where {$_.Tag.Name -eq $VSPHERE_TAG_NAME}).Entity
This next section creates the HCX mappings between the source and destination vSphere endpoints:
$targetDatastore = Get-HCXDatastore -Site $targetSite -Name $TARGET_DATASTORE_NAME $targetContainer = Get-HCXContainer -Site $targetSite -Type "ResourcePool" -Name $TARGET_RESOURCE_POOL_NAME $targetFolder = Get-HCXContainer -Site $targetSite -Type Folder -Name $TARGET_VM_FOLDER_NAME $sourceSite = Get-HCXSite -Source $targetSite = Get-HCXSite -Destination $mobilityGroupConfig = New-HCXMobilityGroupConfiguration -SourceSite $sourceSite -DestinationSite $targetSite
Now we construct our HCX Migration configuration which is based on the list of VMs we filtered out earlier. In most examples you find online, it only demonstrates how to do this with a single VM which is interesting but not that useful if you are looking to migrate multiple VMs and this is where HCX Mobility Group shines.
$hcxMigrations = @() foreach ($vm in $vms) { $hcxVm = Get-HCXVM -Name $VM.Name $sourceNetwork = $hcxVm.Network[0] $targetNetwork = Get-HCXNetwork -Type NsxtSegment -Name $TARGET_NETWORK_NAME -Site $targetSite $networkMapping = New-HCXNetworkMapping -SourceNetwork $sourceNetwork -DestinationNetwork $targetNetwork $hcxMigration = New-HCXMigration -VM $hcxVm ` -MigrationType $MIGRATION_TYPE ` -SourceSite $sourceSite ` -DestinationSite $targetSite ` -DiskProvisionType SameAsSource ` -RetainMac $true ` -TargetComputeContainer $targetContainer ` -TargetDatastore $targetDatastore ` -NetworkMapping $networkMapping ` -Folder $targetFolder ` -MobilityGroupMigration $hcxMigrations += $hcxMigration }
After we have our HCX Migration configuration stored in $hcxMigrations variable, we then create our HCX Mobility Group:
$mobilityGroup = New-HCXMobilityGroup -Name $MOBILITY_GROUP_NAME -Migration $hcxMigrations -GroupConfiguration $mobilityGroupConfig
Before initiating a migration with HCX Mobility Group, we can actually test and validate our configuration. To do so, simply use Test-HCXMobiltyGroup cmdlet:
Test-HCXMobilityGroup -MobilityGroup $mobilityGroup
Finally, start the migration, use the Start-HCXMobilityGroupMigration cmdlet:
Start-HCXMobilityGroupMigration -MobilityGroup $mobilityGroup
Here is a copy of the entire script for those that just want to copy/paste:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$VC_SERVER="vcsa.vmware.corp" | |
$VC_USERNAME="*protected email*" | |
$VC_PASSWORD="VMware1!" | |
$HCX_SERVER="hcx.vmware.corp" | |
$VSPHERE_TAG_CATEGORY="Cloud" | |
$VSPHERE_TAG_NAME="VMC" | |
# vMotion, Bulk, Cold, RAV, OsAssistedMigration | |
$MIGRATION_TYPE="RAV" | |
$TARGET_NETWORK_NAME="L2E_HOL-10-f58e483b" | |
$TARGET_DATASTORE_NAME="WorkloadDatastore" | |
$TARGET_RESOURCE_POOL_NAME="Compute-ResourcePool" | |
$TARGET_VM_FOLDER_NAME="Workloads" | |
$MOBILITY_GROUP_NAME="VMworld-2020-Demo" | |
Connect-VIServer -Server $VC_SERVER -User $VC_USERNAME -Password $VC_PASSWORD -Force | Out-Null | |
Connect-HCXServer -Server $HCX_SERVER -User $VC_USERNAME -Password $VC_PASSWORD | Out-Null | |
$vms = (Get-TagAssignment -Category $VSPHERE_TAG_CATEGORY | where {$_.Tag.Name -eq $VSPHERE_TAG_NAME}).Entity | |
$targetDatastore = Get-HCXDatastore -Site $targetSite -Name $TARGET_DATASTORE_NAME | |
$targetContainer = Get-HCXContainer -Site $targetSite -Type "ResourcePool" -Name $TARGET_RESOURCE_POOL_NAME | |
$targetFolder = Get-HCXContainer -Site $targetSite -Type Folder -Name $TARGET_VM_FOLDER_NAME | |
$sourceSite = Get-HCXSite -Source | |
$targetSite = Get-HCXSite -Destination | |
$mobilityGroupConfig = New-HCXMobilityGroupConfiguration -SourceSite $sourceSite -DestinationSite $targetSite | |
$hcxMigrations = @() | |
foreach ($vm in $vms) { | |
$hcxVm = Get-HCXVM -Name $VM.Name | |
$sourceNetwork = $hcxVm.Network[0] | |
$targetNetwork = Get-HCXNetwork -Type NsxtSegment -Name $TARGET_NETWORK_NAME -Site $targetSite | |
$networkMapping = New-HCXNetworkMapping -SourceNetwork $sourceNetwork -DestinationNetwork $targetNetwork | |
$hcxMigration = New-HCXMigration -VM $hcxVm ` | |
-MigrationType $MIGRATION_TYPE ` | |
-SourceSite $sourceSite ` | |
-DestinationSite $targetSite ` | |
-DiskProvisionType SameAsSource ` | |
-RetainMac $true ` | |
-TargetComputeContainer $targetContainer ` | |
-TargetDatastore $targetDatastore ` | |
-NetworkMapping $networkMapping ` | |
-Folder $targetFolder ` | |
-MobilityGroupMigration | |
$hcxMigrations += $hcxMigration | |
} | |
$mobilityGroup = New-HCXMobilityGroup -Name $MOBILITY_GROUP_NAME -Migration $hcxMigrations -GroupConfiguration $mobilityGroupConfig | |
Test-HCXMobilityGroup -MobilityGroup $mobilityGroup | |
Start-HCXMobilityGroupMigration -MobilityGroup $mobilityGroup | |
Disconnect-VIServer * -Confirm:$false | Out-Nul |
Brad Hendrickson says
Is it possible to specify a specific service mesh for each mobility group? To spread the load around?
Brad Hendrickson says
Any ideas on how to accomplish this?
MOMO says
after executing the script the service mesh showing not available. and this is actually blocking the sync. can you help with this? thank you.