Hi.
Having 'borrowed' the code to set Traffic Shaping on a Port Group from Alan (Renouf) Virtu-Al it works a treat. I noticed earlier that having set all my port groups up with VLAN IDs the Traffic Shaping overwrites the value of my VMotion Port Group to zero.
Foreach ($PG in ($VMHost | Get-VirtualSwitch -Name "vSwitch0" | Get-VirtualPortGroup))
{
$vswitchName = "vSwitch0"
$pgName = $PG.Name
if ( $pgName -match "vmotion" -eq $true )
{
Write-Host " ---> Found VMotion switch, applying Traffic Shaping policy." -Backgroundcolor Black -ForegroundColor White
$HS = $VMHost | Get-View
$nwSys = $HS.ConfigManager.NetworkSystem
$mor = Get-View $nwSys
$portgrp = New-Object VMware.Vim.HostPortGroupSpec
$portgrp.Name = $pgName
$portgrp.VswitchName = $vswitchName
$portgrp.policy = New-Object VMware.Vim.HostNetworkPolicy
$portgrp.policy.shapingPolicy = New-Object VMware.Vim.HostNetworkTrafficShapingPolicy
$portgrp.policy.shapingPolicy.enabled = $true
$portgrp.policy.shapingPolicy.averageBandwidth = 700000000
$portgrp.policy.shapingPolicy.peakBandwidth = 700000000
$portgrp.policy.shapingPolicy.burstSize = 1
$mor.UpdatePortGroup($pgName, $portgrp)
}
}
I assume there must be a value I add into the $portgroup but I've yet to understand what it is.
Any assistance is appreciated and rewarded with points.
Cheers,
Darren.
The HostPortGroupSpec object contains the VlanId property and by default it is set to 0 (zero).
Just copy the value from the $PG variable and you should be ok.
$vswitchName = <vswitchname> $tgtPg = <portgroupname> foreach ($VMHost in Get-VMHost) { foreach ($PG in ($VMHost | Get-VirtualSwitch -Name $vswitchName | Get-VirtualPortGroup)) { $pgName = $PG.Name # check virtual switch name, match any spelling variant of vMotion if ( $pgName -match $tgtPg) { Write-Host " ---> Found VMotion switch, applying Traffic Shaping policy." -Backgroundcolor Black -ForegroundColor White $HS = $VMHost | Get-View $nwSys = $HS.ConfigManager.NetworkSystem $mor = Get-View $nwSys $portgrp = New-Object VMware.Vim.HostPortGroupSpec $portgrp.Name = $pgName $portgrp.VswitchName = $vswitchName $portgrp.policy = New-Object VMware.Vim.HostNetworkPolicy $portgrp.policy.shapingPolicy = New-Object VMware.Vim.HostNetworkTrafficShapingPolicy $portgrp.policy.shapingPolicy.enabled = $true $portgrp.policy.shapingPolicy.averageBandwidth = 700000000 $portgrp.policy.shapingPolicy.peakBandwidth = 700000000 $portgrp.policy.shapingPolicy.burstSize = 1 $portgrp.VlanId = $PG.VLanId $mor.UpdatePortGroup($pgName, $portgrp) } } }
Btw I changed some other things to optimise the code
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The HostPortGroupSpec object contains the VlanId property and by default it is set to 0 (zero).
Just copy the value from the $PG variable and you should be ok.
$vswitchName = <vswitchname> $tgtPg = <portgroupname> foreach ($VMHost in Get-VMHost) { foreach ($PG in ($VMHost | Get-VirtualSwitch -Name $vswitchName | Get-VirtualPortGroup)) { $pgName = $PG.Name # check virtual switch name, match any spelling variant of vMotion if ( $pgName -match $tgtPg) { Write-Host " ---> Found VMotion switch, applying Traffic Shaping policy." -Backgroundcolor Black -ForegroundColor White $HS = $VMHost | Get-View $nwSys = $HS.ConfigManager.NetworkSystem $mor = Get-View $nwSys $portgrp = New-Object VMware.Vim.HostPortGroupSpec $portgrp.Name = $pgName $portgrp.VswitchName = $vswitchName $portgrp.policy = New-Object VMware.Vim.HostNetworkPolicy $portgrp.policy.shapingPolicy = New-Object VMware.Vim.HostNetworkTrafficShapingPolicy $portgrp.policy.shapingPolicy.enabled = $true $portgrp.policy.shapingPolicy.averageBandwidth = 700000000 $portgrp.policy.shapingPolicy.peakBandwidth = 700000000 $portgrp.policy.shapingPolicy.burstSize = 1 $portgrp.VlanId = $PG.VLanId $mor.UpdatePortGroup($pgName, $portgrp) } } }
Btw I changed some other things to optimise the code
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Many many thanks for, once again, jumping to the rescue and also for the code tweaking.
Points awarded.
Cheers,
Darren.