VMware PowerCLI

The Best User Interface for your VMware Datacenter!

Set-NetworkAdapter does not support attaching VMs to NSX-T Logical Switches

Currently, the Set-NetworkAdapter cmdlet is not aware of NSX-T Logical Switches which are backed by the OpaqueNetwork network type. This prevents customers from being able to easily change or attach a VM to an NSX-T Logical Switch and would have to resort to the "Views" to be able to reconfigure the VM. 

The following snippet was recently shared from few NSBU folks and it would be great if we can extend support for NSX-T Logical Switches

$vm = Get-VM
$adapter = $vm | Get-NetworkAdapter
$opaqueNetwork = Get-View -ViewType OpaqueNetwork
$opaqueNetworkBacking = New-Object VMware.Vim.VirtualEthernetCardOpaqueNetworkBackingInfo
$opaqueNetworkBacking.OpaqueNetworkId = $opaqueNetwork.Summary.OpaqueNetworkId
$opaqueNetworkBacking.OpaqueNetworkType = $opaqueNetwork.Summary.OpaqueNetworkType
$device = $adapter.ExtensionData
$device.Backing = $opaqueNetworkBacking
$spec = New-Object VMware.Vim.VirtualDeviceConfigSpec
$spec.Operation = [VMware.Vim.VirtualDeviceConfigSpecOperation]::edit
$spec.Device = $device
$configSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$configSpec.DeviceChange = @($spec)
$vm.ExtensionData.ReconfigVM($configSpec)

 

  • William Lam
  • Jun 8 2018
  • Planned
  • Attach files