Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# Grab VM object from HCX (Cannot be from vCenter)
$vm = Get-HCXVM -Name "NameofVM"
# If you have multiple sources or destination, you would need to augment with parameters such as name, server(hcxserver), and/or id.
$sourceSite = Get-HCXSite -Source
$targetSite = Get-HCXSite -Destination
# Source and target networks assume just one network adapter.
# For more than one adapter, you would need to loop through each source adapter and add to $NetworkMapping array.
$sourceNetwork = $vm.Network[0]
$targetNetwork = Get-HCXNetwork -Type Network -Name "VM Network" -Site $targetSite
$networkMapping = New-HCXNetworkMapping -SourceNetwork $sourceNetwork -DestinationNetwork $targetNetwork
# Here you define the target datastore/clusters/resource pools/folders/storageprofiles.
$targetDatastore = Get-HCXDatastore -Site $targetSite -Name "vsanDatastore"
$targetContainer = Get-HCXContainer -Site $targetSite -Name "vSANRP1" -Type "ResourcePool"
$targetFolder=Get-HCXContainer -Site $targetSite -Type Folder -Name "vSAN_VM_Folder"
$targetStorageProfile = Get-HCXStorageProfile -Site $targetSite -Name "vSAn, storage"
# To create a <HCXMobilityGroupMigration[]> array of objects, the key is the -MobilityGroupMigration switch to flag the cmdlet to output as such.
$newMigration1 = New-HCXMigration -DestinationSite $targetSite -DiskProvisionType SameAsSource -ForcePowerOffVm $true -MigrationType Bulk -RemoveISOs $true -RemoveSnapshots $true -RetainMac $true -SourceSite $sourceSite -TargetComputeContainer $targetContainer -TargetDatastore $targetDatastore -UpgradeHardware $true -UpgradeVMTools $true -VM $vm -NetworkMapping $networkMapping -MobilityGroupMigration
# To create an HCX Mobility Group Configuration. Basically a way to set common parameters for all your migrations. SourceSite and Destination Site are required parameters.
$NewGC = New-HCXMobilityGroupConfiguration -SourceSite $HcxSrcSite -DestinationSite $HcxDstSite
# To create a new hcx mobility group, you actually need to pass three parameters. Name, <HCXMobilityGroupMigration[]> object, and <HCXMobilityGroupConfiguration> to the migration parameter, not just name as suggested in help.
$mobilityGroup1 = New-HCXMobilityGroup -Name hcxMG1PowerCLI-2 -Migration $newMigration1 -GroupConfiguration $NewGC
# Captures the Mobility group object so you can see how everything is configured.
$mg = Get-HCXMobilityGroup -Name "hcxMG1PowerCLI-6" -Detailed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.