A vSphere distributed switch lets you handle networking traffic for all associated hosts in a data center. After you create a new vSphere distributed switch in PowerCLI, you can add hosts and connect virtual machines to it.

Prerequisites

Verify that you are connected to a vCenter Server system.

Procedure

  1. Get the data center where you want to create the vSphere distributed switch.
    $myDatacenter = Get-Datacenter -Name "MyDatacenter"
  2. Get all hosts in your data center.
    $vmHosts = $myDatacenter | Get-VMHost
  3. Create a new vSphere distributed switch.
    $myVDSwitch = New-VDSwitch -Name "MyVDSwitch" -Location $myDatacenter
    The distributed switch is created with no port groups.
  4. Add the hosts in your data center to the distributed switch.
    Add-VDSwitchVMHost -VDSwitch $myVDSwitch -VMHost $vmHosts
  5. Get a physical network adapter from your hosts.
    $hostsPhysicalNic = $vmHosts | Get-VMHostNetworkAdapter -Name "vmnic2"
  6. Add the physical network adapter to the distributed switch that you created.
    Add-VDSwitchPhysicalNetworkAdapter -VMHostNetworkAdapter $hostsPhysicalNic -DistributedSwitch $myVDSwitch
  7. Create a new distributed port group with 1000 ports and add it to the distributed switch.
    $myVDPortGroup = New-VDPortgroup -Name "MyVMsPortGroup" -VDSwitch $myVDSwitch -NumPorts 1000
  8. Connect all virtual machines running on the hosts in your data center to the distributed port group.
    $vmHosts | Get-VM | Get-NetworkAdapter | Set-NetworkAdapter -PortGroup $myVDPortGroup

What to do next

Adjust the settings of the distributed switch. See Configure a Distributed Switch.