A description of port groups has already been given in the Using standard port groups section. In this section, you will learn how to use port groups on Distributed Virtual Switches.
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. The first parameter set is the default one:
New-VDPortgroup [-VDSwitch] <VDSwitch> -Name <String>
[-Notes <String>] [-NumPorts <Int32>] [-VlanId <Int32>]
[-VlanTrunkRange <VlanRangeList>] [-PortBinding
<DistributedPortGroupPortBinding>] [-RunAsync]
[-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
The second parameter set can be used to create a port group from a reference port group:
New-VDPortgroup [-VDSwitch] <VDSwitch> [-Name <String>]
-ReferencePortgroup <VDPortgroup> [-RunAsync] [-Server <VIServer[]>]
[-WhatIf] [-Confirm] [<CommonParameters>]
The third parameter set can be used to create a port group from an export:
New-VDPortgroup [-VDSwitch] <VDSwitch> [-Name <String>] -BackupPath
<String> [-KeepIdentifiers] [-RunAsync] [-Server <VIServer[]>]
[-WhatIf] [-Confirm] [<CommonParameters>]
The -VDSwitch
, -Name
, -ReferencePortgroup
, and -BackupPath
parameters are required.
The following example creates a new distributed virtual port group on the vSphere Distributed Switch VDSwitch2
with 64 ports and VLAN ID 10
:
PowerCLI C:> Get-VDSwitch -Name VDSwitch2 | >> New-VDPortgroup -Name "VLAN 10 Port Group" -NumPorts 64 -VLanId 10 Name NumPorts PortBinding ---- -------- ----------- VLAN 10 Port Group 64 Static
In the following example, we will create a new distributed virtual port group named VLAN 10 Port group 2
using the VLAN 10 Port Group
port group as a reference:
PowerCLI C:> $Portgroup = Get-VDPortgroup -Name 'VLAN 10 Port Group' PowerCLI C:> Get-VDSwitch -Name VDSwitch2 | >> New-VDPortgroup -Name 'VLAN 10 Port group 2' -ReferencePortgroup $Portgroup Name NumPorts PortBinding ---- -------- ----------- VLAN 10 Port group 2 64 Static
In the last example of this section, we will create a new distributed virtual port group named VLAN 10 Port group 3
using an export. Later in this chapter, in the
Exporting the configuration of distributed virtual port groups
section, we will show you how to create an export of a distributed virtual port group.
PowerCLI C:> Get-VDSwitch -Name VDSwitch2 | >> New-VDPortgroup -Name 'VLAN 10 Port group 3' -BackupPath c: 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
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. The first parameter set is the default:
Get-VDPortgroup [[-Name] <String[]>] [-NetworkAdapter
<NetworkAdapter[]>] [-VDSwitch <VDSwitch[]>]
[-VMHostNetworkAdapter <HostVirtualNic[]>] [-Server <VIServer[]>]
[-Tag <Tag[]>] [<CommonParameters>]
The second parameter set is for retrieving distributed virtual port groups by ID:
Get-VDPortgroup -Id <String[]> [-Server <VIServer[]>]
[<CommonParameters>]
The third parameter set is for retrieving distributed virtual port groups by related object:
Get-VDPortgroup -RelatedObject <VDPortgroupRelatedObjectBase[]>
[<CommonParameters>]
The -Id
or the -RelatedObject
parameter is required if you want to retrieve a distributed virtual port group by ID or related object.
In the following example, we will retrieve all of our distributed virtual port groups:
PowerCLI C:> Get-VDPortGroup Name NumPorts PortBinding ---- -------- ----------- VDSwitch2-DVUplinks-86 4 Static VDSwitch3-DVUplinks-88 0 Static VDSwitch4-DVUplinks-90 0 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 distributed virtual port groups, to roll back distributed virtual port groups to their 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. The first parameter set is the default:
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>]
The second parameter set is for rolling back distributed virtual port groups to its last valid configuration:
Set-VDPortgroup -RollbackConfiguration [-VDPortgroup] <VDPortgroup[]>
[-RunAsync] [-Server <VIServer[]>] [-WhatIf] [-Confirm]
[<CommonParameters>]
The third parameter set is for importing the configuration of distributed virtual port groups from a backup:
Set-VDPortgroup -BackupPath <String> [-VDPortgroup] <VDPortgroup[]>
[-RunAsync] [-Server <VIServer[]>] [-WhatIf] [-Confirm]
[<CommonParameters>]
The -VDPortGroup
, -RollbackConfiguration
, and -BackupPath
parameters are required.
In the following example, we will rename distributed virtual port group VLAN 10 Port Group 2
to VLAN 10 Port Group 4
, and modify the number of ports to 128
:
PowerCLI C:> Get-VDPortgroup -Name 'VLAN 10 Port Group 2' | >> Set-VDPortgroup -Name 'VLAN 10 Port Group 4' -NumPorts 128 Name NumPorts PortBinding ---- -------- ----------- VLAN 10 Port Group 4 128 Static
In the following example, we will roll back the configuration of distributed virtual port group VLAN 10 Port Group 4
to its last valid configuration using the following command:
PowerCLI C:> Get-VDPortgroup -Name 'VLAN 10 Port Group 4' | >> Set-VDPortgroup -RollbackConfiguration Name NumPorts PortBinding ---- -------- ----------- VLAN 10 Port Group 2 64 Static
As you can see in the output of the preceding command, the port group name is returned to VLAN 10 Port Group 2
, and the number of ports is set back to 64
.
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 Export-VDPortgroup
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
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.
In the following example, we will enable Network I/O Control for the VDSwitch2
switch using the EnableNetworkResourceManagement()
method from the API:
PowerCLI C:> $VDSwitch = Get-VDSwitch -Name VDSwitch2 PowerCLI C:> $VDSwitch.ExtensionData .EnableNetworkResourceManagement($true)
The preceding command does not return any output.
You can check if Network I/O Control is enabled on vSphere Distributed Switch VDSwitch2
, using the following PowerCLI commands:
PowerCLI C:> $VDSwitch = Get-VDSwitch -Name VDSwitch2 PowerCLI C:> $VDSwitch.ExtensionData.Config .NetworkResourceManagementEnabled True
Because the output of the preceding command is True
, you know that Network I/O Control is enabled on vSphere Distributed Switch VDSwitch2.
Disabling Network I/O Control for VDSwitch1
can be done by replacing $true
in the preceding example with $false
:
PowerCLI C:> $VDSwitch = Get-VDSwitch -Name VDSwitch2 PowerCLI C:> $VDSwitch.ExtensionData .EnableNetworkResourceManagement($false)
The preceding command does not return any output.
You can make an export of one or more distributed virtual port groups with the Export-VDPortGroup
cmdlet. You can 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>]
The -VDPortGroup
parameter is required.
In the following 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/29/2017 11:23 AM 1865 Vlan10PortGroup.zip
In the following example, we will use the Set-VMHostNetworkAdapter
cmdlet, which we have seen before in the
Configuring host network adapters
section, 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 Name ---- --- ----------- -- ---------- ------ vmk1 00:50:56:6c:a8:38 False 192.168.0.150 255.255.255.0 vmk1
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>]
The -VDPortGroup
parameter is required.
In the following example, we will remove the port group named VLAN 10 Port Group 3
:
PowerCLI C:> Get-VDPortGroup -Name 'VLAN 10 Port Group 3' | >> Remove-VDPortGroup -Confirm:$false
The preceding command does not return any output.
18.217.220.114