Set-NicTeamingPolicy in Esxi via Powershell

In VMware vSphere, you can use PowerCLI (PowerShell module for VMware) to manage various aspects of ESXi hosts and virtual infrastructure. To set NIC teaming policies on a vSwitch or port group, you can use the Set-NicTeamingPolicy cmdlet. Here’s an example of how you can use it:

# Connect to your vCenter Server
Connect-VIServer -Server YourVCenterServer -User YourUsername -Password YourPassword

# Get the ESXi host
$ESXiHost = Get-VMHost -Name "YourESXiHostName"

# Get the vSwitch or port group
$vSwitchName = "vSwitch0"           # Specify the name of your vSwitch
$portGroupName = "Management Network"  # Specify the name of your port group

# Retrieve the existing NIC teaming policy
$nicTeamingPolicy = Get-NicTeamingPolicy -VMHost $ESXiHost -VSwitch $vSwitchName -PortGroup $portGroupName

# Modify the NIC teaming policy settings
$nicTeamingPolicy.LoadBalancing = "iphash"  # Set load balancing policy (example: "iphash")
$nicTeamingPolicy.NotifySwitches = $true     # Set switch notification setting

# Apply the modified NIC teaming policy
Set-NicTeamingPolicy -NicTeamingPolicy $nicTeamingPolicy -VMHost $ESXiHost -VSwitch $vSwitchName -PortGroup $portGroupName

# Disconnect from the vCenter Server
Disconnect-VIServer -Server * -Confirm:$false

Remember to replace YourVCenterServer, YourUsername, YourPassword, YourESXiHostName, vSwitch0, and Management Network with your actual vCenter Server details, ESXi host name, vSwitch name, and port group name.

In this script:

  1. Connect to the vCenter Server using Connect-VIServer.
  2. Get the ESXi host using Get-VMHost.
  3. Retrieve the existing NIC teaming policy using Get-NicTeamingPolicy.
  4. Modify the NIC teaming policy settings as needed.
  5. Apply the modified NIC teaming policy using Set-NicTeamingPolicy.
  6. Disconnect from the vCenter Server using Disconnect-VIServer.

Leave a comment