Seems like a well hidden gem.
I would like to script all the details of creating a dvswitch and this is the last piece I cannot figure out.
I would like to set "NFS Traffic" to High and "vMotion traffic" to Low via PowerCLI.
Can anyone assist?
thanks
Bear with me here. This may not look very elegant, but it'll get the job done. There doesn't seem to be any direct cmdlets for editing those values. Had to resort to other methods and properties on the objects.
You'll need your standard Connect-VIServer and Disconnect-VIServer cmdlets (just assumed you knew that already).
You may also need to change what's in the quotes in the $dvs line with the Get-VDSwitch command. In my example, my default switch name on my lab device was "dvSwitch"
==========================================================
$dvs = (Get-VDSwitch -Name "dvSwitch").ExtensionData
$netShares = $dvs.NetworkResourcePool | Where {$_.Name -match "vMotion|NFS"} | Sort Name
$newSpec = New-Object Vmware.Vim.DVSNetworkResourcePoolConfigSpec[](2)
$i = 0
foreach ($shareItem in $netShares)
{
$newSpec[$i] = New-Object VMware.Vim.DVSNetworkResourcePoolConfigSpec
$newSpec[$i].Key = $netShares[$i].Key
$newSpec[$i].Name = $netShares[$i].Name
$newSpec[$i].Description = $netShares[$i].Description
$newSpec[$i].ConfigVersion = $netShares[$i].ConfigVersion
$newSpec[$i].AllocationInfo = $netShares[$i].AllocationInfo
if ($newSpec.Name -match "vMotion") { $newSpec[$i].AllocationInfo.Shares.Level = "low" }
else { $newSpec[$i].AllocationInfo.Shares.Level = "high" } #assume NFS since vMotion was checked before hand
$i++
}
$dvs.UpdateNetworkResourcePool($newSpec)
==================================================================
What this does is essentially copy existing NetworkPool information into the ConfigSpec objects and then edits the $newSpec.AllocationInfo.Shares object (specifically, Level) to change from low to high (or normal if you wanted to set that). Specifically, this should get you to what you need (I hope!)
Bear with me here. This may not look very elegant, but it'll get the job done. There doesn't seem to be any direct cmdlets for editing those values. Had to resort to other methods and properties on the objects.
You'll need your standard Connect-VIServer and Disconnect-VIServer cmdlets (just assumed you knew that already).
You may also need to change what's in the quotes in the $dvs line with the Get-VDSwitch command. In my example, my default switch name on my lab device was "dvSwitch"
==========================================================
$dvs = (Get-VDSwitch -Name "dvSwitch").ExtensionData
$netShares = $dvs.NetworkResourcePool | Where {$_.Name -match "vMotion|NFS"} | Sort Name
$newSpec = New-Object Vmware.Vim.DVSNetworkResourcePoolConfigSpec[](2)
$i = 0
foreach ($shareItem in $netShares)
{
$newSpec[$i] = New-Object VMware.Vim.DVSNetworkResourcePoolConfigSpec
$newSpec[$i].Key = $netShares[$i].Key
$newSpec[$i].Name = $netShares[$i].Name
$newSpec[$i].Description = $netShares[$i].Description
$newSpec[$i].ConfigVersion = $netShares[$i].ConfigVersion
$newSpec[$i].AllocationInfo = $netShares[$i].AllocationInfo
if ($newSpec.Name -match "vMotion") { $newSpec[$i].AllocationInfo.Shares.Level = "low" }
else { $newSpec[$i].AllocationInfo.Shares.Level = "high" } #assume NFS since vMotion was checked before hand
$i++
}
$dvs.UpdateNetworkResourcePool($newSpec)
==================================================================
What this does is essentially copy existing NetworkPool information into the ConfigSpec objects and then edits the $newSpec.AllocationInfo.Shares object (specifically, Level) to change from low to high (or normal if you wanted to set that). Specifically, this should get you to what you need (I hope!)
Well, does not seem to apply for latest vSphere 6
--
Exception calling "UpdateNetworkResourcePool" with "1" argument(s): "
Required parameter configSpec is missing
while parsing call information for method UpdateNetworkResourcePool
at line 1, column 218
while parsing SOAP body
at line 1, column 207
while parsing SOAP envelope
at line 1, column 38
while parsing HTTP request for method updateNetworkResourcePool
on object of type vim.DistributedVirtualSwitch
at line 1, column 0"
At C:\scripts\newreplication.ps1:40 char:1
+ $dvs.UpdateNetworkResourcePool($newSpec)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
Any tips?