Skip to content

Instantly share code, notes, and snippets.

@Zsoldier
Last active May 15, 2020 04:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zsoldier/feef3ca5d8d221bc5c469363ddbaf7e3 to your computer and use it in GitHub Desktop.
Save Zsoldier/feef3ca5d8d221bc5c469363ddbaf7e3 to your computer and use it in GitHub Desktop.
# 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