Home > Blogs > VMware PowerCLI Blog


Managing VDS with PowerCLI

With the release of vSphere 5.0 and 5.1 I have seen people become more confident with using the vSphere Distributed Switch (VDS), this is probably due to some of the great new features that make the switch not only easier to manage but also less error prone when configuring, more manageable from the backup/restore point of view and top this off with some great new features and I can see why people are moving to the VDS from other existing visualized switching configurations.

Some great examples of these additions can be found here:

On the operational aspects of networking other network switches can have a CLI to manage them, people who are moving to the VDS often wonder what options are available to them and how they can give access to the networking team to manage their networking environment.

With the introduction of PowerCLI 5.1 R2 we added a VDS Snap-in, this means we can now manage the VDS with PowerCLI but of course other areas of operational management already existing in PowerCLI with the existing vSphere cmdlets.  Whilst this is not a complete replacement for the well known networking CLIs this is certainly a place that I have seen some network admins move to and once they learn the differences they are surprised by the ease of use and the quick results they can achieve.

To show some of the ease of use and power I put together some specific code examples based around networking:

List the commands for working with VDS

Get-VDSCommand

List all VMs and their Network Portgroup and Mac Address

Get-VM | Get-NetworkAdapter | Select Parent, Name, NetworkName, MacAddress

Export the configuration of a specified port group to file

Get-VDPortGroup -Name ‘DHCP01’ | Export-VDPortGroup -Destination ‘C:\MyVDSwitchesBackup\DHCP01BackupPG.zip’

List all Portgroups and their relevant information

Get-VDPortgroup | Select Name, VirtualSwitch, Datacenter, VlanConfiguration, NumPorts, PortBinding

List the vSwitches and their main properties

Get-VDSwitch | Select *

Create a new distributed port group on the specified vSphere distributed switch with the specified number of ports and VLAN ID

Get-VDSwitch -Name “Test-VDS” | New-VDPortgroup -Name “PG_VLAN4” -NumPorts 8 -VLanId 4

Switch settings can be altered with the Set-VDSwitch cmdlet, an example of this is how to enable link discovery protocol on a specified vSphere distributed switch, set it to LLDP and change the link discovery protocol operation to listen.

$myVDSwitch = Get-VDSwitch -Name “Test-VDS”
Set-VDSwitch -VDSwitch $myVDSwitch -LinkDiscoveryProtocol LLDP -LinkDiscoveryProtocolOperation Listen

Modify the maximum number of ports, the number of uplink ports, and the maximum MTU size of the specified vSphere distributed switch.

Get-VDSwitch -Name “Test-VDS” | Set-VDSwitch -MaxPorts 1000 -NumUplinkPorts 8 -Mtu 2000

Change the name, number of ports and the VLAN ID of all distributed port groups named “MyVDPortGroup”

Get-VDPortgroup -Name “PG_VLAN4” | Set-VDPortgroup -Name “PG_VLAN5” -NumPorts 5 -VlanId 5

If your network team has reservation around moving to the VDS, I strongly advise getting them to take a look at PowerCLI to see what they can achieve and remember, with the .Extensiondata property and the Get-View cmdlet they can open up the entire API for VDS and achieve the parts that there is currently not a cmdlet for.

This entry was posted in Network and tagged , , on by .
Alan Renouf

About Alan Renouf

Alan Renouf is a Product Line Manager at VMware focusing on API's, SDK's and CLI's, He is responsible for providing the architects and operators of private and public cloud infrastructure with the toolkits/frameworks and command-line interfaces they require to build a fully automated software-defined datacenter. Alan is a frequent blogger at http://blogs.vmware.com/PowerCLI a book author and has a personal blog at http://virtu-al.net. You can follow Alan on twitter as @alanrenouf.

8 thoughts on “Managing VDS with PowerCLI

  1. Lord2y

    Why there aren’t cmdlets for managing uplinks?

    Reply
    1. Alan RenoufAlan Renouf Post author

      We normally hit the features which will be most used and pick up from there, keep an eye on future versions of PowerCLI.

      Reply
  2. Pingback: Managing VDS with PowerCLI (vSphere PowerCLI Blog) | VMware News

  3. automater

    Hi Alan,

    I was searching on a way to configure LACP interface on VDS.Currently this is done using the vSphere web client.Is thare a way to do it using the powerCLI.

    Reply
  4. Martin Kölbl

    Is there a way to get to avilable or used ports of a porgroup?

    I want to make a check, if there are portgroups with no free ports left.

    Reply
  5. Stuart

    You should be able to get there using something like the below

    Get-cluster MyClusterName | get-vmhost | get-random | Get-VDSwitch | where { $_.Name -like “*Internal*” } | Get-VDPortgroup | where { $_.NumPorts -ge 0 -and $_.NumPorts -le 100 -and $_.Name -NotLike “*Build*” -and $_.Name -NotLike “*DVUplinks*”}

    Reply
    1. Martin Kölbl

      Hi Stuart,

      thanks for the reply.

      The command you suggested tells me only if there are portgroups with less or equal 100 ports. But it doesn’t tell me how much of them are used by virutal machines.

      Reply
  6. aenagy

    This command returns blank for “VirtualSwitch” (PowerCLI 5.8 R1 on Windows 7 x64, vSphere 5.5):

    Get-VDPortgroup | Select Name, VirtualSwitch, Datacenter, VlanConfiguration, NumPorts, PortBinding

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

*