I have an ESX 5.0 U2 Cluster intended for hosting Internet-facing VMs. The hosts are configured with a pair of uplinks trunked to internal "management" VLANs and another pair of uplinks trunked to internet VLANs. I created a single VDS utilizing these 4 uplinks. Next, I wanted to modify my script used for adding port groups to a VDS from a CSV to set the Failover Order as shown in the following screen capture:
With the assistance of Onyx and the SDK Documentation on VMwareUplinkPortOrderPolicy, I though that I had found the answer. Unfortunately, my script does not set the mgmt-dvUplinks to "Unused." Given the SDK does not appear to provide a property for Unused, I guess this is not really surprising, but I am still hopeful there is a way to do this. Please help!
Here is my PowerCLI script:
param (
$datacenter = $(throw "A datacenter is required"),
$dvSwitchName = $(throw "A dvSwitchName is required."),
$pgFile = $(throw "pgFile is required. Should be CSV and contain Prefix,VLAN,Subnet")
)
$dvs = Get-VirtualSwitch -Distributed -Datacenter $datacenter -Name $dvSwitchName
if (!$dvs) {
exit 1
}
#Data needed is Prefix,VLAN,Subnet,Untagged
$pgData = @(Import-Csv $pgFile | Where-Object {$_.VLAN -ne $null})
if ($pgData.Length -eq 0) {
Write-Host "No port group data in the file."
exit 1
}
$vPgGroupSpec = New-Object VMware.Vim.DVPortgroupConfigSpec[]($pgData.Length)
for ($i=0; $i -lt $pgData.Length; $i++) {
$vPgGroupSpec[$i] = New-Object Vmware.Vim.DVPortgroupConfigSpec
$pgData[$i].VLAN = [int]$pgData[$i].VLAN
$pgName = "{0}{1:D4}_{2}" -f $pgData[$i].Prefix, $pgData[$i].VLAN, $pgData[$i].Subnet
Write-Host $pgName
$vPgGroupSpec[$i].type = "earlyBinding"
$vPgGroupSpec[$i].Name = $pgName
$vPgGroupSpec[$i].numPorts = 300
$vPgGroupSpec[$i].defaultPortConfig = New-Object Vmware.Vim.VMwareDVSPortSetting
# VLAN Info
$vPgGroupSpec[$i].defaultPortConfig.vlan = New-Object Vmware.Vim.VmwareDistributedVirtualSwitchVlanIdSpec
$vPgGroupSpec[$i].defaultPortConfig.vlan.inherited = $false
if ($pgData[$i].Untagged -match "TRUE")
{
$vPgGroupSpec[$i].defaultPortConfig.vlan.vlanId = 0
}
else
{
$vPgGroupSpec[$i].defaultPortConfig.vlan.vlanId = $pgData[$i].VLAN
}
$vPgGroupSpec[$i].type = "earlyBinding"
# Security Policy
$vPgGroupSpec[$i].defaultPortConfig.securityPolicy = New-Object Vmware.Vim.DVSSecurityPolicy
$policyFalse = New-Object VMware.Vim.BoolPolicy
$policyFalse.value = $false
$vPgGroupSpec[$i].defaultPortConfig.securityPolicy.allowPromiscuous = $policyFalse
$vPgGroupSpec[$i].defaultPortConfig.securityPolicy.forgedTransmits = $policyFalse
$vPgGroupSpec[$i].defaultPortConfig.securityPolicy.macChanges = $policyFalse
# Teaming Policy
$vPgGroupSpec[$i].defaultPortConfig.uplinkTeamingPolicy = New-Object Vmware.Vim.VmwareUplinkPortTeamingPolicy
$vPgGroupSpec[$i].defaultPortConfig.uplinkTeamingPolicy.policy = New-Object VMware.Vim.StringPolicy
$vPgGroupSpec[$i].defaultPortConfig.uplinkTeamingPolicy.policy.value = "loadbalance_loadbased"
# This is the part that does not work as intended
$vPgGroupSpec[$i].defaultPortConfig.uplinkTeamingPolicy.uplinkPortOrder = New-Object VMware.Vim.VMwareUplinkPortOrderPolicy
$vPgGroupSpec[$i].defaultPortConfig.uplinkTeamingPolicy.uplinkPortOrder.inherited = $false
$vPgGroupSpec[$i].defaultPortConfig.uplinkTeamingPolicy.uplinkPortOrder.activeUplinkPort = New-Object System.String[]
$vPgGroupSpec[$i].defaultPortConfig.uplinkTeamingPolicy.uplinkPortOrder.activeUplinkPort[0] = "inter-dvUplink1"
$vPgGroupSpec[$i].defaultPortConfig.uplinkTeamingPolicy.uplinkPortOrder.activeUplinkPort[1] = "inter-dvUplink2"
}
$dvs.ExtensionData.AddDVPortgroup($vPgGroupSpec)