Introduction to vSphere Distributed switches

Exclusive offer: get 50% off this eBook here
Learning PowerCLI

Learning PowerCLI — Save 50%

A practical guide to get you started with automating VMware vSphere via PowerCLI with this book and ebook

$26.99    $13.50
by Robert van den Nieuwendijk | February 2014 | Enterprise Articles Networking & Telephony

This article by Robert van den Nieuwendijk, the author of Learning PowerCLI, gives you a brief introduction on managing virtual networks with PowerCLI. VMware vSphere provides two types of virtual switches that you can use to configure the networks: vSphere Standard Switches and vSphere Distributed Switches. The vSphere Standard Switches are specific for an ESXi server host. The vSphere Distributed Switches are created and centrally managed on a vCenter Server and are copied to every host that uses this vSphere Distributed Switch.

(For more resources related to this topic, see here.)

Using vSphere Distributed Switches

The vSphere Distributed Switches are virtual switches that span across multiple hosts. This makes it easier to configure hosts that need similar network configurations. It also ensures that virtual machines will get the same network configuration when they migrate to another host. You need a vSphere Enterprise Plus license and a vCenter Server to be able to use vSphere Distributed Switches.

In vSphere PowerCLI, there are separate sets of cmdlets for working with vSphere Standard Switches and vSphere Distributed Switches. In the past, the VMware PowerCLI team tried to integrate both types of switches into one set of cmdlets. This is why, for example, the Get-VirtualSwitch cmdlet has a –Distributed parameter. However, this parameter is now obsolete, and VMware made a new set of cmdlets specific for vSphere Distributed Switches. The vSphere PowerCLI VDS snap-in that provides support for managing Distributed Switches and port groups was introduced in PowerCLI 5.1 Release 2. In this section, you will learn more about these new cmdlets.

In the following diagram, you see a vSphere Distributed Switch that spans two hosts:

Creating vSphere Distributed Switches

The New-VDSwitch cmdlet creates new vSphere Distributed Switches. This cmdlet has the following syntax:

New-VDSwitch [-ContactDetails <String>] [-ContactName <String>] [-LinkDiscoveryProtocol <LinkDiscoveryProtocol>] [-LinkDiscoveryProtocolOperation <LinkDiscoveryOperation>] [-MaxPorts <Int32>] [-Mtu <Int32>] [-Notes <String>] [-NumUplinkPorts <Int32>] [-Version <String>] -Name <String> -Location <VIContainer> [-RunAsync] [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>] New-VDSwitch -ReferenceVDSwitch <VDSwitch> -Name <String> -Location <VIContainer> [-WithoutPortGroups] [-RunAsync] [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>] New-VDSwitch -BackupPath <String> [-KeepIdentifiers] [-Name <String>] -Location <VIContainer> [-WithoutPortGroups] [-RunAsync] [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

If you compare the preceding syntax with the syntax of the New-VirtualSwitch cmdlet, then you will see that the New-VDSwitch cmdlet has many more possibilities to configure the virtual switch during creation. In vSphere 5.1 and later versions, you can even specify a reference vSphere Distributed Switch or a backup profile from where a new switch can be created.

Creating a new vSphere Distributed Switch from scratch.

To create a new vSphere Distributed Switch from scratch, you have to specify at least the -Name and the –Location parameters. The location can be a datacenter or a folder.

In the next example. we will create a new vSphere Distributed Switch named VDSwitch1 in datacenter New York:

PowerCLI C:\> $Datacenter = Get-Datacenter -Name "New York" PowerCLI C:\> New-VDSwitch -Name "VDSwitch1" -Location $Datacenter Name NumPorts Mtu Version Vendor ------------------------------------------------------------------------ VDSwitch2 0 1500 5.5.0 VMware

Cloning a vSphere Distributed Switch

We can now clone the VDSwitch1 to a new switch VDSwitch2. Of course, this is not very useful because VDSwitch1 is not configured yet. We will clone the switch just to show you how to do it:

PowerCLI C:\> New-VDSwitch -Name "VDSwitch2" `
>> -ReferenceVDSwitch "VDSwitch1" -Location $Datacenter
>>
Name NumPorts Mtu Version Vendor
---- -------- --- ------- ------
VDSwitch2 0 1500 5.5.0 VMware

If you want to clone a vSpheredistributed switch without cloning the port groups, then you can use the –WithoutPortGroups parameter.

Cloning a vSphere Distributed Switch and the New-VDSwitch-ReferenceVDSwitch parameter are only supported in VMware vSphere 5.1 and later versions.

Creating a vSphere Distributed Switch from an export

Later in this article, we will see how to create an export of the configuration of a vSphere Distributed Switch. If you have an export, then you can use it to recreate a switch or to create a new one. The next example will create a new vSphere Distributed Switch named VDSwitch3 in the datacenter New York from an export of the configuration of VDSwitch1:

PowerCLI C:\> New-VDSwitch -BackupPath C:\VDSwitch1Config.zip ` >> -Name VDSwitch3 -Location (Get-Datacenter –Name "New York") Importing vSphere distributed switch - Switch name: 'VDSwitch1', Switch version: 5.5.0, Number of port groups: 1, Number of resource pools: 8, Number of uplinks: 1, Notes: VDSwitch1 Configuration Name NumPorts Mtu Version Vendor ------------------------------------------------------------------------ VDSwitch3 0 1500 5.5.0 VMware

Also, for importing an export you can use the –WithoutPortGroups parameter to prevent importing the port groups.

Retrieving vSphere Distributed Switches

You can retrieve vSphere Distributed Switches with the Get-VDSwitch cmdlet. The syntax of this cmdlet is as follows:

Get-VDSwitch [[-Name] <String[]>] [-Location <FolderContainer[]>] [-VMHost <VMHost[]>] [-VM <VirtualMachine[]>] [-Server <VIServer[]>] [<CommonParameters>] Get-VDSwitch -Id <String[]> [-Server <VIServer[]>] [<CommonParameters>] Get-VDSwitch -RelatedObject <VDSwitchRelatedObjectBase[]> [<CommonParameters>]

If you use the Get-VDSwitch cmdlet without parameters, then it will return all of the vSphere Distributed Switches in your environment. You can use the -Location parameter to specify a datacenter or folder in which you want to search for vSphere Distributed Switches.

The next example will retrieve all of the vSphere Distributed Switches in the datacenter New York:

PowerCLI C:\> Get-Datacenter -Name "New York" | Get-VDSwitch Name NumPorts Mtu Version Vendor -------------------------------------------------------------- VDSwitch1 0 1500 5.5.0 VMware VDSwitch2 0 1500 5.5.0 VMware VDSwitch3 0 1500 5.5.0 VMware

You can specify a value for the –Name parameter to retrieve a specific vSphere Distributed Switch. In the following example, we will retrieve the vSphere Distributed Switch VDSwitch1:

PowerCLI C:\> Get-VDSwitch -Name VDSwitch1 Name NumPorts Mtu Version Vendor ------------------------------------------------------------------------ VDSwitch1 0 1500 5.5.0 VMware

Configuring vSphere Distributed Switches

The selection you make using Get-VDSwitch can be used as an input of the SetVDSwitch cmdlet to modify the configuration or version of one or more vSphere Distributed Switches, to roll back the configuration to its previous state, or to import the configuration from a backup profile.

Rolling back the configuration of a vSphere Distributed Switch and importing the configuration of a vSphere Distributed Switch from a backup are available only on vSphere 5.1 and later versions.

The Set-VDSwitchcmdlet has the following syntax:

Set-VDSwitch [-Name <String>] [-ContactDetails <String>] [-ContactName <String>] [-LinkDiscoveryProtocol <LinkDiscoveryProtocol>] [-LinkDiscoveryProtocolOperation <LinkDiscoveryOperation>] [-MaxPorts <Int32>] [-Mtu <Int32>] [-Notes <String>] [-NumUplinkPorts <Int32>] [-Version <String>] [-VDSwitch] <VDSwitch[]> [-RunAsync] [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>] Set-VDSwitch -BackupPath <String> [-WithoutPortGroups] [-VDSwitch] <VDSwitch[]> [-RunAsync] [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>] Set-VDSwitch -RollBackConfiguration [-VDSwitch] <VDSwitch[]> [-RunAsync] [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

In the next example, we will set almost every property for VDSwitch1 that you can set using PowerShell. We will use a PowerShell technique called splatting to create a parameter list for the Set-VDSwitch cmdlet. The parameter list will be a hash table called $Parameters. By using the splat operator @,you can add the parameters in the $Parameters hash table to the Set-VDSwitchcmdlet call.

When you use splatting, you have to use the name of the variable containing the parameter's hash table without the dollar sign, that is, @Parameters and not @$Parameters.

PowerCLI C:\> $VDSwitch = Get-VDSwitch -Name vDSWitch1 PowerCLI C:\> $Parameters = @{ >> NumUplinkPorts = 2 >> MaxPorts = 1024 >> LinkDiscoveryProtocol = 'LLDP' >> LinkDiscoveryProtocolOperation = 'Both' >> ContactName = 'vsphereadmin@blackmilktea.com' >> ContactDetails = 'New York office' >> Notes = 'VDSwitch for New York datacenter' >> } >> $VDSwitch | Set-VDSwitch @Parameters >> Get-VDSwitch -Name vDSWitch1 | Format-List -Property * >> Name NumPorts Mtu Version Vendor ------------------------------------------------------------- VDSwitch1 0 1500 5.5.0 VMware LinkDiscoveryProtocol : LLDP LinkDiscoveryProtocolOperation : Both VlanConfiguration : Name : VDSwitch1 ExtensionData : VMware.Vim. VmwareDistributedVirtualSwitch NumPorts : 0 Key : 6c 48 12 50 ca 61 ec be-4d a8 bb 95 d0 0f bd a7 Mtu : 1500 Notes : VDSwitch for New York datacenter Datacenter : New York NumUplinkPorts : 4 ContactName : vsphereadmin@blackmilktea.com ContactDetails : New York office Version : 5.5.0 Vendor : VMware Folder : network MaxPorts : 1024 Id : VmwareDistributedVirtualSwitch-dvs-182 Uid : /VIServer=root@192.168.0.132:443/Distrib utedSwitch=VmwareDistributedVirtualSwitch-dvs-49/ Client : VMware.VimAutomation.Vds.Impl. V1.VDClientImpl

The following screenshot of the vSphere Web Client shows the settings of the Distributed Switch VDSwitch1 after executing the previous commands:

Rolling back the configuration of a vSphere Distributed Switch

If you made a mistake in the configuration of a vSphere Distributed Switch, then you can roll back the configuration to its previous state using the Set-VDSwitch –RollbackConfiguration parameter

In the following example, we will modify the MTU size of the switch VDSwitch1to 9,000, and then use the –RollbackConfigurationparameter to revert to the previous value of 1,500:

PowerCLI C:\> Get-VDSwitch -Name VDSwitch1 | >> Set-VDSwitch -MTU 9000 >> Name NumPorts Mtu Version Vendor -------------------------------------------------------------- VDSwitch1 0 9000 5.5.0 VMware PowerCLI C:\> Get-VDSwitch -Name VDSwitch1 | >> Set-VDSwitch –RollbackConfiguration >> Name NumPorts Mtu Version Vendor ------------------------------------------------------------ VDSwitch1 0 1500 5.5.0

Importing the configuration of a vSphere Distributed Switch from a backup

You can import the configuration of a vSphere Distributed Switch from a backup created with the Export-VDSwitch cmdlet. Later in this article, you will learn how to create a backup. In this section, we will show you how to restore the configuration from a backup.

You have to use the Set-VDSwitch -BackupPath parameter to specify the path to the configuration .zip file. You can also use the –WithoutPortGroups parameter if you don't want to restore the port groups.

In the next example, we will import the configuration of VDSwitch1 from a backup file called 'c:\myVDSwitch1Config.zip':

PowerCLI C:\> Get-VDSwitch -Name 'VDSwitch1' | >> Set-VDSwitch -BackupPath 'c:\myVDSwitch1Config.zip' >> Restoring vSphere distributed switch configuration - Switch name: 'VDSwitch1', Switch version: 5.5.0, Number of port groups: 0, Number of resource pools: 8, Number of uplinks: 1, Notes: My VDSwitch1 configuration Name NumPorts Mtu Version Vendor ------------------------------------------------------------- VDSwitch1 0 1500 5.5.0

Upgrading a vSphere Distributed Switch

In every new VMware vSphere version, VMware introduces new features to the vSphere Distributed Switch. To be able to use these new features, you have to upgrade your switches to the new version.

In the next example, we will upgrade the version of the VDSwitch4 switch to 5.5.0:

PS C:\> $VDSwitch = Get-VDSwitch -Name VDSwitch4 PS C:\> $VDSwitch Name NumPorts Mtu Version Vendor ---------------------------------------------------------------- VDSwitch4 0 1500 4.1.0 VMware PS C:\> $VDSwitch | Set-VDSwitch -Version 5.5.0 Name NumPorts Mtu Version Vendor --------------------------------------------------------------- VDSwitch4 0 1500 5.5.0 VMware

Adding hosts to vSphere Distributed Switches

After creating a vSphere Distributed Switch, you have to add hosts to the switch. Normally, you add at least all of the hosts that are in the same cluster. Because a vSphere Distributed Switch is created in a datacenter or a folder, a vSphere Distributed Switch is not limited to one cluster. You can add hosts of multiple clusters to the same switch.

The Add-VDSwitchVMHost cmdlet will add hosts to a vSphere Distributed Switch. The syntax of this cmdlet is as follows:

Add-VDSwitchVMHost -VDSwitch <VDSwitch> -VMHost <VMHost[]> [-Server <VIServer[]>] [-RunAsync] [-WhatIf] [-Confirm] [<CommonParameters>]

In the next example, we will add all of the hosts of the cluster "Cluster01" to the vSphere Distributed Switch "VDSwitch1":

PowerCLI C:\> $VMHost = Get-Cluster Cluster01 | Get-VMHost PowerCLI C:\> Add-VDSwitchVMHost -VDSwitch VDSwitch1 -VMHost $VMHost

Learning PowerCLI A practical guide to get you started with automating VMware vSphere via PowerCLI with this book and ebook
Published: February 2014
eBook Price: $26.99
Book Price: $44.99
See more
Select your format and quantity:

Adding host physical network adapters to a vSphere Distributed Switch

Adding hosts to a vSphere Distributed Switch does not add physical network adapters to the switch. For each host, you have to add network adapters to the vSphere Distributed Switch to give the switch connectivity to the external network.

The Add-VDSwitchPhysicalNetworkAdapter cmdlet will connect a host's physical network adapter to a vSphere Distributed Switch. The syntax of this cmdlet is as follows:

Add-VDSwitchPhysicalNetworkAdapter [-VMHostNetworkAdapter] <PhysicalNic[]> [-DistributedSwitch] <DistributedSwitch> [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

The following example will add the physical network adapter vmnic4 of the host 192.168.0.133 to the vSphere Distributed Switch VDSwitch1:

PowerCLI C:\> $NetworkAdapter = Get-VMHost -Name 192.168.0.133 | >> Get-VMHostNetworkAdapter -Name vmnic4 -Physical >> PowerCLI C:\> Add-VDSwitchPhysicalNetworkAdapter ` >> -DistributedSwitch VDSwitch1 ` >> -VMHostNetworkAdapter $NetworkAdapter -Confirm:$false >>

Removing host physical network adapters from a vSphere Distributed Switch

Removing a physical network adapter from a vSphere Distributed Switch can be done using the Remove -VDSwitchPhysicalNetworkAdapter cmdlet. The syntax of this cmdlet is as follows:

Remove-VDSwitchPhysicalNetworkAdapter [-VMHostNetworkAdapter] <PhysicalNic[]> [-WhatIf] [-Confirm] [<CommonParameters>]

You have to specify only a network adapter as the value of the –VMHostNetworkAdapter parameter; then the cmdlet will remove that network adapter from the switch to which it is connected.

In the following example, the physical network adapter vmnic4 from the host 192.168.0.133 will be removed from the vSphere Distributed Switch VDSwitch1:

PowerCLI C:\> Get-VMhost -Name 192.168.0.133 | >> Get-VMHostNetworkAdapter -Physical -Name vmnic4 | >> Remove-VDSwitchPhysicalNetworkAdapter -Confirm:$false >>

Removing hosts from a vSphere Distributed Switch

You can use the Remove-VDSwitchVMHost cmdlet to remove a host from a vSphere Distributed Switch. This cmdlet has the following syntax:

Remove-VDSwitchVMHost -VDSwitch <VDSwitch> -VMHost <VMHost[]> [-Server <VIServer[]>] [-RunAsync] [-WhatIf] [-Confirm] [<CommonParameters>]

In the next example, we will remove the host 192.168.0.133 from the vSphere Distributed Switch VDSwitch1:

PowerCLI C:\> Get-VDSwitch -Name VDSwitch1 | >> Remove-VDSwitchVMHost -VMHost 192.168.0.133 -Confirm:$false >>

Exporting the configuration of vSphere Distributed Switches

If you export the configuration of a vSphere Distributed Switch, then you can create a .zip file that can be used as a backup for the configuration of the vSphere Distributed Switch. You can use this .zip file to recreate or clone the vSphere Distributed Switch.

The Export-VDSwitch cmdlet that you can use to create the .zip file has the following syntax:

Export-VDSwitch [-VDSwitch] <VDSwitch[]> [-WithoutPortGroups] [-Description <String>] [-Destination <String>] [-Force] [-Server <VIServer[]>] [<CommonParameters>]

The next PowerCLI example will export the configuration of the vSphere Distributed Switch VDSwitch1 into a file called VDSwitch1Config.zip:

PowerCLI C:\> Get-VDSwitch -Name VDSwitch1 |

>> Export-VDSwitch -Description "VDSwitch1 Configuration" ` >> -Destination "c:\VDSwitch1Config.zip" >> Mode LastWriteTime Length Name ---- -------------------------------------------------------------- --a--- 1/9/2014 6:51 PM 4374 VDSwitch1Config.zip

Removing vSphere Distributed Switches

To remove a vSphere Distributed Switch, you can use the Remove-VDSwitch cmdlet. This cmdlet has the following syntax:

Remove-VDSwitch [-VDSwitch] <VDSwitch[]> [-RunAsync] [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

In the next example, we will remove the vSphere Distributed Switch VDSwitch1:

PowerCLI C:\> Get-VDSwitch -Name VDSwitch1 | >> Remove-VDSwitch -Confirm:$false >>

Using distributed virtual port groups

In this section, you will learn how to use port groups on Distributed Virtual Switches.

Creating distributed virtual port groups

You can use the New-VDPortgroup cmdlet to create distributed virtual port groups from scratch, from the reference port groups, or from an export of a Distributed Virtual Switch. The syntax of the New-VDPortgroup cmdlet is as follows:

New-VDPortgroup [-VDSwitch] <VDSwitch> -Name <String> [-Notes <String>] [-NumPorts <Int32>] [-VlanId <Int32>] [-VlanTrunkRange <VlanRangeList>] [-PortBinding <DistributedPortGroupPortBinding>] [-RunAsync] [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>] New-VDPortgroup [-VDSwitch] <VDSwitch> [-Name <String>] -ReferencePortgroup <VDPortgroup> [-RunAsync] [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>] New-VDPortgroup [-VDSwitch] <VDSwitch> [-Name <String>] -BackupPath <String> [-KeepIdentifiers] [-RunAsync] [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

The New-VDPortgroup cmdlet has three parameter sets. The first parameter set is the default one, the second parameter set can be used to create a port group from a reference port group, and the third one can be used to create a port group from an export.

The first example creates a new distributed virtual port group on the vSphere Distributed Switch VDSwitch1 with 64 ports and VLAN ID 10:

PowerCLI C:\> Get-VDSwitch -Name VDSwitch1 |

>> New-VDPortgroup -Name "VLAN 10 Port Group" -NumPorts 64 -VLanId 10 >> Name NumPorts PortBinding ---- ------------------------------------------ ------------------- VLAN 10 Port Group 64 Static

Creating distributed virtual port groups from a reference group

In the following example, we will create a new distributed virtual port group named VLAN 10 Port group 2 using the port group VLAN 10 Port Group as a reference:

PowerCLI C:\> $Portgroup = Get-VDPortgroup -Name 'VLAN 10 Port Group' PowerCLI C:\> Get-VDSwitch -Name VDSwitch1 | >> New-VDPortgroup -Name 'VLAN 10 Port group 2' -ReferencePortgroup $Portgroup >> Name NumPorts PortBinding ------------ ------------------------------------------------------- VLAN 10 Port group 2 64 Static

Creating distributed virtual port groups from a reference group and the New-VDPortgroup -ReferencePortgroup parameter are only supported in VMware vSphere 5.1 and later versions.

Creating distributed virtual port groups from an export

This is the last example of this section. In this one, we will create a new distributed virtual port group named VLAN 10 Port group 3 using an export. Later in this article, we will show you how to create an export of a distributed virtual port group.

PowerCLI C:\> Get-VDSwitch -Name VDSwitch1 | >> New-VDPortgroup -Name 'VLAN 10 Port group 3' -BackupPath c:\users\ robert\vlan10portgroup.zip >> Restoring vSphere distributed port group configuration - Name: VLAN 10 Port Group, VLAN: 'Access: 10', Type: standard, Port binding: static, Port allocation: elastic, Notes: Name NumPorts PortBinding ---- -------- ------------------------------------------------- VLAN 10 Port group 3 64 Static

Configuring distributed virtual port groups

You can use the Get-VDPortgroup cmdlet to retrieve all of your distributed virtual port groups or to retrieve a specific one. The syntax of this cmdlet is as follows:

Get-VDPortgroup [[-Name] <String[]>] [-NetworkAdapter <NetworkAdapter[]>] [-VDSwitch <VDSwitch[]>] [-VMHostNetworkAdapter <HostVirtualNic[]>] [-Server <VIServer[]>] [-Tag <Tag[]>] [<CommonParameters>] Get-VDPortgroup -Id <String[]> [-Server <VIServer[]>] [<CommonParameters>] Get-VDPortgroup -RelatedObject <VDPortgroupRelatedObjectBase[]> [<CommonParameters>]

In the following example, we will retrieve all of our distributed virtual port groups:

PowerCLI C:\> Get-VDPortGroup Name NumPorts PortBinding ---- -------- ---------------------------------------------------- VDSwitch1-DVUplinks-182 4 Static VLAN 10 Port group 64 Static VLAN 10 Port group 2 64 Static VLAN 10 Port group 3 64 Static

The Set-VDPortgroup cmdlet can be used to modify the configuration of a distributed virtual port group, to roll back the distributed virtual port group to its last valid configuration, or to import the configuration from a .zip file created earlier with the Export-VDPortgroup cmdlet. The syntax of the Set-VDPortgroup cmdlet is as follows:

Set-VDPortgroup [-Name <String>] [-Notes <String>] [-NumPorts <Int32>] [-VlanId <Int32>] [-VlanTrunkRange <VlanRangeList>] [-PrivateVlanId <Int32>] [-PortBinding <DistributedPortGroupPortBinding>] [-DisableVlan] [-VDPortgroup] <VDPortgroup[]> [-RunAsync] [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>] Set-VDPortgroup -RollbackConfiguration [-VDPortgroup] <VDPortgroup[]> [-RunAsync] [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>] Set-VDPortgroup -BackupPath <String> [-VDPortgroup] <VDPortgroup[]> [-RunAsync] [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

Learning PowerCLI A practical guide to get you started with automating VMware vSphere via PowerCLI with this book and ebook
Published: February 2014
eBook Price: $26.99
Book Price: $44.99
See more
Select your format and quantity:

Renaming a distributed virtual port group

In the following example, we will rename distributed virtual port group VLAN 10 Port Group 2 to VLAN 20 Port Group, modify the number of ports to 128, and change the VLAN ID to 20:

PowerCLI C:\> Get-VDPortgroup -Name 'VLAN 10 Port Group 2' | >> Set-VDPortgroup -Name 'VLAN 20 Port Group' -NumPorts 128 -VlanId 20 >> Name NumPorts PortBinding ---- -------- -------------------------------------------------- VLAN 20 Port Group 128 Static

In the following screenshot of the vSphere Web Client, the port group is shown after it is renamed to VLAN 20 Port Group:

Rolling back the configuration of a distributed virtual port group

In the following example, we will roll back the configuration of distributed virtual port group VLAN 10 Port Group to its last valid configuration using the following command:

PowerCLI C:\> Get-VDPortgroup -Name 'VLAN 10 Port Group' | >> Set-VDPortgroup -RollbackConfiguration >> Name NumPorts PortBinding ---- -------- -------------------------------------------- VLAN 10 Port Group 64 Static

Restoring the configuration of a distributed virtual port group

In the following example, we will restore the configuration of distributed virtual port group VLAN 10 Port Group from a .zip file created earlier using the ExportVDPortgroup cmdlet:

PowerCLI C:\> Get-VDPortgroup -Name 'VLAN 10 Port Group' | >> Set-VDPortgroup -BackupPath c:\Vlan10PortGroup.zip >> Applying vSphere distributed port group configuration -

Name: VLAN 10 Port Group, VLAN: 'Access: 10', Type: standard,

Port binding: static, Port allocation: elastic, Notes: Name NumPorts PortBinding ---- -------- --------------------------------------------- VLAN 10 Port Group 64 Static

Configuring Network I/O Control

The virtual Distributed Switch cmdlets don't have a method to configure Network I/O Control. However, in PowerCLI you can use all of the VMware vSphere public APIs. It is not difficult to use them to enable or disable Network I/O Control.

Enabling Network I/O Control

In the following example, we will enable Network I/O Control for switch VDSwitch1 using the EnableNetworkResourceManagement() method from the API:

PowerCLI C:\> $VDSwitch = Get-VDSwitch -Name VDSwitch1 PowerCLI C:\> $VDSwitch.ExtensionData.EnableNetworkResourceManagement($true)

Disabling Network I/O Control

Disabling Network I/O Control for VDSwitch1 can be done by replacing $true in the previous example with $false:

PowerCLI C:\> $VDSwitch = Get-VDSwitch -Name VDSwitch1 PowerCLI C:\> $VDSwitch.ExtensionData.EnableNetworkResourceManagement($false)

Exporting the configuration of distributed virtual port groups

You can make an export from one or more distributed virtual port groups with the Export-VDPortGroup cmdlet, and later use this export to create new port groups or to restore the configuration of port groups. The syntax of the Export-VDPortGroup cmdlet is as follows:

Export-VDPortGroup [-VDPortGroup] <VDPortgroup[]> [-Description <String>] [-Destination <String>] [-Force] [-Server <VIServer[]>] [<CommonParameters>]

In the next example, we will create an export of VLAN 10 Port Group:

PowerCLI C:\> Get-VDPortGroup -Name 'VLAN 10 Port Group' | >> Export-VDPortGroup -Destination C:\Vlan10PortGroup.zip >> Mode LastWriteTime Length Name ---- --------------------------------------------------------------------- -a--- 1/9/2014 6:57 PM 1865 Vlan10PortGroup.zip

Migrating a host network adapter from a standard port group to a distributed port group

In the next example, we will use the Set-VMHostNetworkAdapter cmdlet, which we have seen before, to migrate the virtual network adapter vmk1 to the distributed port group VLAN 10 Port Group:

PowerCLI C:\> Get-VMHostNetworkAdapter -Name vmk1 | >> Set-VMHostNetworkAdapter -PortGroup 'VLAN 10 Port Group' -Confirm:$false >> Name Mac DhcpEnabled IP SubnetMask Device ---- --- ----------- -- ---------- -------------------------------------------- vmk1 00:50:56:65:bd:a1 False 192.168.0.150 255.255.255.0 vmk1

Removing distributed virtual port groups

To remove a distributed virtual port group, you can use the Remove-VDPortGroup cmdlet. The syntax of this cmdlet is as follows:

Remove-VDPortGroup [-VDPortGroup] <VDPortgroup[]> [-RunAsync] [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

In the following example, we will remove the port group named VLAN 10 Port Group:

PowerCLI C:\> Get-VDPortGroup -Name 'VLAN 10 Port Group' | >> Remove-VDPortGroup -Confirm:$false >>

Summary

In this article, we covered virtual networking. We showed you how to work with vSphere Standard Switches and vSphere Distributed Switches using PowerCLI. You learned to use port groups, to use host network adapters, and how to configure the management network of a host and the network of a virtual machine.

Resources for Article:


Further resources on this subject:


About the Author :


Robert van den Nieuwendijk

Robert van den Nieuwendijk is an IT veteran from the Netherlands with over 25 years of experience in the IT industry. He holds a bachelor's degree in Software Engineering. After working for a few years as a programmer of air traffic control and vessel traffic management systems for a company that is now called HITT, he started his own company Van den Nieuwendijk Informatica in 1988. Since then he has worked as a freelance systems administrator for OpenVMS, Windows Server, Linux, and VMware vSphere systems, mainly for Dutch governmental organizations. Currently, he is a VMware vSphere administrator at Wageningen UR (University and  Research centre). During winter, he is also a ski and snowboard instructor at an indoor ski school.

With his background as a programmer, he always tries to make his job easier by writing programs or scripts to perform repetitive tasks. In the past, he used the C programming language, OpenVMS DCL, Visual Basic Script, and KiXtart to do this. Since Windows PowerShell 1.0, he uses Windows PowerShell and VMware vSphere PowerCLI for all of his scripting work.

Robert is a member of the Dutch VMware User group (VMUG) Customer Council and a frequent contributor and moderator at the VMware VMTN Communities. In 2012 and 2013, VMware awarded him the vExpert title for his "significant contributions to the community and a willingness to share his expertise with others".

He has his own blog at http://rvdnieuwendijk.com where he has shared his knowledge since 2011. He writes mainly about VMware vSphere PowerCLI, Windows PowerShell, and VMware vSphere.

If you want to get in touch with Robert, you can find him on Twitter. His username is  @rvdnieuwendijk.

Books From Packt


VMware vCloud Security
VMware vCloud Security

VMware View Security Essentials
VMware View Security Essentials

VMware ESXi 5.1 Cookbook
VMware ESXi 5.1 Cookbook

Troubleshooting vSphere Storage
Troubleshooting vSphere Storage

vSphere High Performance Cookbook
vSphere High Performance Cookbook

Microsoft System Center Virtual Machine Manager 2012 Cookbook
Microsoft System Center Virtual Machine Manager 2012 Cookbook

Instant VMware vCloud Starter [Instant]
Instant VMware vCloud Starter [Instant]

VMware Horizon View 5.3 Design Patterns and Best Practices
VMware Horizon View 5.3 Design Patterns and Best Practices


Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software