VMware Communities > VMTN > VMware vSphere™ > Automation Tools > vSphere™ PowerCLI > Discussions

This Question is Not Answered

1 "correct" answer available (10 pts) 2 "helpful" answers available (6 pts)
0 Replies Last post: Feb 11, 2009 4:12 PM by c_shanklin
Reply

Reconfigure virtual switches to use IP-based load balancing.

Feb 11, 2009 4:12 PM

Click to view c_shanklin's profile Master c_shanklin 740 posts since
Dec 3, 2007
VMware
Hi,

Someone asked today how to reconfigure all virtual switches to use IP-based load balancing. I decided to post the answer here, hope you find it useful.

# This script will reconfigure all virtual switches with more than 1 NIC to use
# IP-based load balancing.
# NOTE: The script will reconfigure *ALL* virtual switches on *ALL* hosts.
# Change the Get-VMHost statement if that's not what you want.
Get-VMHost | Get-VMHostNetwork | foreach {
	$networkView = $_ | Get-View
	$switches = $networkView.NetworkInfo.Vswitch | Where { $_.Pnic.length -gt 1 }
	foreach ($switch in $switches) {
		$spec = $switch.spec
		$spec.policy.nicTeaming.policy = "loadbalance_ip"
		# Other values are loadbalance_srcmac, loadbalance_srcid (The default), failover_explicit
		$networkView.UpdateVirtualSwitch($switch.Name, $spec)
	}
}
Actions