Last active
May 15, 2020 04:11
-
-
Save Zsoldier/feef3ca5d8d221bc5c469363ddbaf7e3 to your computer and use it in GitHub Desktop.
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
# 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