lamw/vmware-scripts

xNew-VM does not accommodate NSX-T Opaque Networks in the destination vCenter

Opened this issue · 0 comments

Hello,

We're using Azure VMware Services as a DR destination for Horizon, and using xNew-VM to clone on-prem parent VMs up to the Azure SDDC. xNew-VM (as-written) does not correctly create NICs on new VMs in the AVS SDDC because it does not have code coverage for NSX-T "Opaque" networks. I have added the code below, starting after line 145 in the original script, and it seems to work correctly.

     } elseif ($switchtype -eq "nsx") {
        foreach ($vmNetworkAdapter in $vmNetworkAdapters) {
            # New VM Network to assign vNIC
            $vmnetworkname = ($vmnetworks -split ",")[$count]

            # Target the Opaque Network to which we need to connect
            $opaqueNetwork = Get-View -ViewType OpaqueNetwork | ? {$_.Name -eq $vmnetworkname}
            
            # Device Change spec for Opaque Network
            $dev = New-Object VMware.Vim.VirtualDeviceConfigSpec
            $dev.Operation = "edit"
            $dev.Device = $vmNetworkAdapter
            $dev.device.backing = New-Object VMware.Vim.VirtualEthernetCardOpaqueNetworkBackingInfo
            $dev.device.backing.OpaqueNetworkId = $opaqueNetwork.Summary.OpaqueNetworkId
            $dev.device.backing.OpaqueNetworkType = $opaqueNetwork.Summary.OpaqueNetworkType
            $locationSpec.DeviceChange += $dev
            $count++
        } 

Reference:
https://networkinferno.net/powercli-and-opaque-networks
https://blogs.vmware.com/PowerCLI/2019/02/configuring-vms-opaque-networks.html