dvSwitch scripting – Part 9 – Traffic Shaping

Another interesting feature of a dvSwitch is the ability to use bidirectional traffic shaping. Besides the outbound traffic shaping that is available on regular virtual switches, with the dvSwitches we can also have inbound traffic shaping. The traffic shaping is defined with the three known, classical values: average bandwidth, peak and burst size.

Recently there were some threads in the PowerCLI Community that asked how to do this with PowerCLI. Time to add this to our repertoire of PowerCLI dvSwitch functions.


By default traffic shaping is disabled for inbound and outbound traffic.

To remember the difference between ingress and egress, look at it from the point of view of the dvSwitch; ingress is the traffic from the VM to the switch (i.e. incoming traffic) and egress is from the switch to the VM (i.e. outgoing or exit traffic).

The three parameters to control traffic shaping are:

  • average bandwidth: bits per second averaged over time
  • peak bandwidth: maximum amount (in kbps) the portgroup can handle
  • burst size: maximum number of bytes the portgroup is allowed to burst. Is a multiplicative factor that defines how long the bandwidth can exceed the average.

The script


Line 1-120: The Set-dvPgTrafficShaping function

Line 61: When calling methods on distributed virtual switches it is important to pass the ConfigVersion value of the object.

Line 63-89: Handles the Ingress settings

Line 91-117: Handles the Egress settings

Line 67,76,81,88,95,99,104,109,116: When the network shaping settings are define on the portgroup it is important to indicated that property is not inherited from the dvSwitch.

Line 70,80,98,108: The function parameters allow to specify the average and peak bandwidth values in the Kbps, while the actual call requires these values to be passed in bps. Note that to convert from Kbps to bps you have to multiply by 1000, not 1024.

Line 75,103: The function parameters for the burst size expects values in KB, just like in the vSphere Client. The method itself requires these values to be in bytes.

Line 1-120: The Get-dvPgTrafficShaping function.

Line 143: The result is returned as PSObject to which the properties with the packet shaping values are added.

Sample usage

By default, a new dvSwitch and new dvPortgroup will have traffic shaping disabled.
To get the actual settings we can do

This produces output likes this

Btw, the Get-dvSwitch and Get-dvSwPg functions are described in previous episodes of my dvSwitch series.

To enable inbound and outbound traffic shaping you can call the function as follows

This will result in

And in the vSphere Client this will show as follows.

Notice how we had to call the Get-dvSwPg function again before the Get-dvPgTrafficShaping function. This is required to fetch the actual values for the portgroup.

To enable inbound and disable outbound traffic shaping, you can make the following call.

The result looks like this

To change specific values (average/peak/burst) you can use the function as follows

This call only changes the burst value, the average and peak values are kept as they are, indicated by the -1 values.

And finally a somewhat more advanced example, we use the Get function combined with the Set function to increase the inbound peak bandwidth with 10%.

The result



    Alan Renouf

    As always a fantastic post, your dvSwitch table of all the cmdlets you have written deserves a dedicated page of it’s own so it can be found in your menu nice and easy.

    Awesome stuff


    Steve Jin

    Hi Luc,

    Great post again! The script builds on top of vSphere API directly, therefore a good/easy target to port to Java on open source VI Java API. May do it later and invite you to review. 🙂



      Thanks Steve.

Leave a Reply

Your email address will not be published.


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