View Only
  • 1.  Powercli HCX automation

    Posted Jul 26, 2023 04:01 PM

    I'm brand new to HCX, so have very limited experience with it.

    But running into an issue on how to assign source & desination groups when there's more than one NIC, and more than one subnet.

    Roughly, this is what I have:

    $SrcPortgroup = ($vm | Get-virtualportgroup).Name
    $DstPortgroup = (Get-VDPortgroup -VDSwitch (get-vdswitch | where {$_.Name -like "*$DstPortCluster*"}) | where {$_.Name -like "*$subnet*"}).Name #select the right vds for the right cluster with the right subnet
    $SrcNetwork = Get-HCXNetwork -Name $SrcPortgroup -type DistributedVirtualPortgroup -Site $HcxSrcSite
    $DstNetwork = Get-HCXNetwork -Name $DstPortgroup -type DistributedVirtualPortgroup -Site $HcxDstSite
    $NetworkMapping = New-HCXNetworkMapping -SourceNetwork $SrcNetwork -DestinationNetwork $DstNetwork
    $NewMigration = New-HCXMigration -VM $HcxVM -MigrationType RAV -SourceSite $HcxSrcSite -DestinationSite $HcxDstSite `
    -TargetComputeContainer $DstCompute -TargetDatastore $DstDatastore -NetworkMapping $NetworkMapping
    Do I just do a loop of (foreach $NIC) and make $NetworkMapping an array? or do I loop the portgroups & the $SrcPortgroup/$DstPortgroup be arrays? Or do I have to make $NewMigration an array, which seems weird to me, conceptually for just multiple NICs.

  • 2.  RE: Powercli HCX automation
    Best Answer

    Posted Jul 31, 2023 08:39 PM

    Turns out you have to loop on $NetworkMapping. And if you don't get all the NICs, it will fail.



    My version of it:

    $networkAdapterList = @()
    $NetworkMapping = @()
    $networkAdapterList = $vm | get-networkadapter #vcenter vm, not HCX vm

    for($j = 0; $j -le ($networkAdapterList.Count -1); $j++){
    $SrcNetwork = $HCXvm.Network[$j] #HCXvm, not vcenter vm
    $DstNetwork = Get-HCXNetwork -Name $DstPortgroup -Site $HcxDstSite
    $NetworkMapping += New-HCXNetworkMapping -SourceNetwork $SrcNetwork -DestinationNetwork $DstNetwork