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

Verify that you are connected to a vCenter Server system.


Get the datacenter where you want to create the vSphere distributed switch.

$myDatacenter = Get-Datacenter -Name "MyDatacenter"

Get all hosts in your datacenter.

$vmHosts = $myDatacenter | Get-VMHost

Create a new vSphere distributed switch.

$myVDSwitch = New-VDSwitch -Name "MyVDSwitch" -Location $myDatacenter

The distributed switch is created with no port groups.


Add the hosts in your datacenter to the distributed switch.

Add-VDSwitchVMHost -VDSwitch $myVDSwitch -VMHost $vmHosts

Get a physical network adapter from your hosts.

$hostsPhysicalNic = $vmHosts | Get-VMHostNetworkAdapter -Name "vmnic2"

Add the physical network adapter to the distributed switch that you created.

Add-VDSwitchPhysicalNetworkAdapter -VMHostNetworkAdapter $hostsPhysicalNic -DistributedSwitch $myVDSwitch

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

Connect all virtual machines running on the hosts in your datacenter to the distributed port group.

$vmHosts | Get-VM | Get-NetworkAdapter | Set-NetworkAdapter -PortGroup $myVDPortGroup

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