Using PowerCLI to Get and Set DVS Traffic Shaping Settings

Share on:

I have been in process in configuring traffic shaping for multiple port groups. It seems with PowerCLI 6.3 R1 there are no native Powershell Cmdlets. Luckily I stumbled across @Lucd and his PowerCLI functions to manage these settings, i have put these into a script to mass get and set the settings for all port groups of a DVS’s.


Preparing to Execute the Script

The script is pretty straight forward, just need to define a few variables seen below and then you execute the script. I will walk you through the process.

This script assumes you have already launched PowerCLI and modified the variables

Get Traffic Shaping Settings

1Foreach ($VirtualSwitch in Get-VirtualSwitch -Distributed)  {
2  Foreach ($VirtualPortGroup in Get-VirtualPortGroup -VirtualSwitch $VirtualSwitch|Where {$_.Name -notlike "*DVUplinks*"}) {
3      Write "$VirtualPortGroup on $VirtualSwitch"
4      $dvPg = Get-dvSwPg -dvSw $VirtualSwitch.ExtensionData -PGName $VirtualPortGroup
5      Get-dvPgTrafficShaping -dvPg $dvPg|ft
6  }

Set Traffic Shaping Settings

2Foreach ($VirtualSwitch in Get-VirtualSwitch -Distributed)  {
3  Foreach ($VirtualPortGroup in Get-VirtualPortGroup -VirtualSwitch $VirtualSwitch|Where {$_.Name -notlike "*DVUplinks*"}) {
4      Write "$VirtualPortGroup on $VirtualSwitch"
5      $dvPg = Get-dvSwPg -dvSw $VirtualSwitch.ExtensionData -PGName $VirtualPortGroup
6      Set-dvPgTrafficShaping -dvPg $dvPg -InShaping -inAverageKbps 10485760 -inBurstKB 102400 -inPeakKbps 10485760 -OutShaping -outAverageKbps 10485760 -outBurstKB 102400 -outPeakKbps 10485760
7   }

Execute the Script

  • Run .\Get-VMwareTrafficShapingSettings.ps1
  • Run .\Set-VMwareTrafficShapingSettings.ps1


comments powered by Disqus

See Also