vSphere Distributed Switch PowerCLI cmdlets

For a long time now when presenting at VMworld or VMUGS I have asked the question – What would you like to see from PowerCLI next ?  The standard answer I get at most of these is vSphere Distributed Switch (VDS) cmdlets !

Luc Dekens did a great job with his series of posts showing how you could create your own VDS advanced functions, these allow you to add the functions to your PowerCLI session and work with VDS, find them here and take a look, they are a great example of how you can expand PowerCLI to support areas not yet written.

So what’s new ?

VMware have now released some PowerCLI cmdlets as a fling which work with VDS and allow you to do most of the common VDS tasks in your vSphere environment.  Please note that this is a fling and therefore not officially supported by VMware.  Having said that we are definitely keen for you to download these and try them out – please make sure you leave feedback as this will help with future versions !

Requirements

Currently there are some strict requirements around these cmdlets:

  • Windows required XP or Windows Server 2003 or 2008 is required  (Windows 7 and Vista are not supported currently)
  • VMware PowerCLI 4.1.1 or later is needed

Getting started

1.  Download the fling from here: http://labs.vmware.com/flings/vdspowercli

2.  Run the installer to install the cmdlets to your machine

3.  When you start PowerCLI run the following at the prompt to add the cmdlets into your session:

Add-PSSnapin VMware.VimAutomation.VdsComponent

4. You can now list the cmdlets available to you for managing VDS by using the following:

Get-Command –Module VMware.VimAutomation.VdsComponent

What do you get ?

The following is a list of the cmdlets and what they are used for:

Name Synopsis
Add-VdsVMHost Add a host to be managed by a vSphere Distributed Switch.
Apply-VdsDVPortPolicyProfile Apply the DVPort policy profile to the specified
DVPortgroup or DVPort.
Export-VdsDVPortgroupProfile Retrieve the configuration from specified DVPortgroup
and exports that to a profile xml file.
Export-VdsDVPortPolicyProfile Retrieve the DVPort policy configuration from specified
DVPortgroup or DVPort and exports
that to a DVPort policy profile xml file.
Export-VdsProfile Retrieve the configuration from specified vSphere
Distributed Switches and exports that to a profile xml file.
Get-Vds Retrieve the vSphere Distributed Switches associated
with a virtual machine/host or in any location.
Get-VdsDistributedPortgroup Retrieve the available vSphere Distributed Port Groups
of name, virtual machines,
and vSphere Distributed Switches in the Location.
Get-VdsDVPort Retrieves the available DVPort on specified
vSphere Distributed Switches or DVPortGroup.
Get-VdsDVPortBlockedPolicy Retrieve the Blocked policy of the specified
DVPortgroup or DVPort.
Get-VdsDVPortgroupPolicy Retrieve the Override DVPortgroup policy of the
specified DVPortgroup.
Get-VdsDVPortSecurityPolicy Retrieve the Security policy of the specified
DVPortgroup or DVPort.
Get-VdsDVPortShapingPolicy Retrieve the Shaping policy of the specified
DVPortgroup or DVPort.
Get-VdsDVPortTeamingPolicy Retrieve the Teaming policy of the specified
DVPortgroup or DVPort.
Get-VdsVMHost Get the hosts managed by a vSphere Distributed Switch.
Move-VdsVMHostNetworkAdapter Move a host network adapter between VSS and VDS.
Supports PhysicalNic and HostVirtualNic
New-Vds Create a new vSphere Distributed Switch in a specific location.
New-VdsDistributedPortgroup Create a new vSphere Distributed Port Group in the specified VDS.
Remove-Vds Remove the specified vSphere Distributed Switches.
Remove-VdsDistributedPortgroup Remove the specified vSphere Distributed Port Groups.
Remove-VdsVMHost Remove a host from a vSphere Distributed Switch.
Set-Vds Reconfigure the specified vSphere Distributed Switch.
Set-VdsDistributedPortgroup Change the properties of the specified
vSphere Distributed Port Group.
Set-VdsDVPort Update the properties of specified DVPort.
Set-VdsDVPortBlockedPolicy Set the Blocked policy for the specified DVPortgroup or DVPort.
Set-VdsDVPortgroupPolicy Set the Blocked policy for the specified DVPortgroup or DVPort.
Set-VdsDVPortSecurityPolicy Set the Blocked policy for the specified DVPortgroup or DVPort.
Set-VdsDVPortShapingPolicy Set the Shaping policy for the specified DVPortgroup or DVPort.
Set-VdsDVPortTeamingPolicy Set the Shaping policy for the specified DVPortgroup or DVPort.

Examples

#Get all VDS in "test" Datacente:
$testvdslist = Get-VDS -Location test

#Update VDS uplink ports number and MTU:
Set-VDS -Vds $vds -NumUplinkPorts 10 -Mtu 2000

#Create VDS with default settings:
New-VDS -Name newvds -Location test

#Remove VDS:
Remove-VDS $vds

#Add VMHost to VDS:
Add-VdsVMHost -VDS $vds -VMHost $vmhost1 -Confirm:$false

#Get all VMHost on specified VDS:
$vmhostlist = Get-VdsVMHost -VDS $vds

#Remove VMHost from VDS:
Remove-VDSVMHost -Vds $vds -VMHost $vmhostlist[1]

#Move VmkNic from Host to VDS:
Move-VdsVMHostNetworkAdapter -VirtualNic $nic -DVPortgroup $dvpg -Confirm:$false

#Get DVPortgroup with Name:
$dvpg = Get-VdsDistributedPortgroup -Name testdvportgroup

#Update DVPortgroup ports number:
Set-VdsDistributedPortgroup -DVPortgroup $dvpg -NumPorts 1000

#Create new DVPortgroup with referenceDVPortgroup:
New-VdsDistributedPortgroup -Name testdvpg1 -Vds $vds -ReferenceDVPortgroup $dvpg

#Remove DVPortgroup:
Get-VdsDistributedPortgroup -Name testdvportgroup | Remove-VdsDistributedPortgroup

#Export VDSProfile file from VDS:
Export-VdsProfile -FilePath ./vdsprofile1.xml -VDS $vds

#Export DVPortgroup Profile file from DVPortgroup:
Export-VdsDVPortgroupProfile -FilePath ./vdsdvpgprofile1.xml -DVPortgroup $dvpg

#Export VdsDVPortPolicyProfile file from DVPort:
Export-VdsDVPortPolicyProfile -FilePath ./dvportpolicyprofile1.xml -DVPort $dvport

#Apply the DVPort policy profile to the specified DVPortgroup:
Apply-VdsDVPortPolicyProfile -FilePath ./dvportpolicyprofile1.xml -DVPortGroup $dvpg

#Create new VDS from profile:
New-VDS -Name testvds -Location $testDC -Profile ./vdsprofile1.xml

#Retrieve the Blocked policy of the specified DVPortgroup:
$policy = Get-VdsDVPortBlockedPolicy -DVPortgroup $dvpg

#Retrieve the Security policy of the specified DVPortgroup:
$policy = Get-VdsDVPortSecurityPolicy -DVPortgroup $dvpg

#Retrieve the Shaping policy of the specified DVPortgroup:
$policy = Get-VdsDVPortShapingPolicy -DVPortgroup $dvpg

#Retrieve the Teaming policy of the specified DVPortgroup:
$policy = Get-VdsDVPortTeamingPolicy -DVPortgroup $dvpg

#Retrieve the DVPortgroup policy of the specified DVPortgroup:
$policy = Get-VdsDVPortgroupPolicy -DVPortgroup $dvpg

#Update the blocked policy for the specified DVPortgroup:
Set-VdsDVPortBlockedPolicy -DVPortgroup $dvpg -Blocked $false

#Update the security policy for the specified DVPort:
Set-VdsDVPortSecurityPolicy -DVPort $dvport -Inherited $false -AllowPromiscuousInherited $false -AllowPromiscuous $true -MacChangesInherited $false -MacChanges $true

#Update the shaping policy for the specified DVPortgroup:
Set-VdsDVPortShapingPolicy -DVPortgroup $dvpg -ShapingType $shapingTypeEnum::InShapingPolicy -BurstSize 1024000 -Enabled $true

#Update the teaming policy for the specified DVPortgroup:
Set-VdsDVPortTeamingPolicy -DVPortgroup $dvpg -LoadBalance "loadbalance_srcid" -NotifySwitches $false -FailBack $true -FailOverDetection "Link status only" -ActiveUplink dvUplink1,dvUplink2 -StandbyUplink dvUplink3,dvUplink4

#Update the DVPortgroup policy for the specified DVPortgroup:
Set-VdsDVPortgroupPolicy -DVPortgroup $dvpg -BlockOverrideAllowed $true -ShapingOverrideAllowed $true
Get DVPort with key and VDS parameters:

$dvport = Get-VdsDVPort -VDS $vds -Key 100

#Update DVPort Name and description:
Set-VdsDVPort -DVPort $dvport -Name "testdvport" -Description "testDVPortDescription"

5 thoughts on “vSphere Distributed Switch PowerCLI cmdlets

  1. Pingback: Get-Scripting Podcast Episode 27 – (The One Where They Catch Up and Share Loads of PowerShell Tips and Tricks) | CrypticZero

  2. Pingback: Top 5 Planet V12N blog posts for week 44 | Download VDI Solutions

  3. Pingback: VMware Labs finally release PowerCLI VDS cmdlet package! | Dan Hayward

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.