Reset Hard "Flapped" Host Nics

Post date: Apr 9, 2016 12:40:14 AM

So I came across a scenario where host nic was down. Rebooting and reseating hardware did nothing. Removing the vSwitch and recreating seemed to resolve the issue. When it happened again days later I tried removing the network adapter and re-adding it back to the vSwitch. That resolved it. I decided to look into scripting this task while the vendors tried to figure this out. Looking at the EsxCLI I noticed that resetting the nic that was down also resolved the issue. So, I made a function. Enjoy!

<################################################################################

.SYNOPSIS

Checks and corrects downed link status on ESXi physical nics.

.DESCRIPTION

Function was created to check and look for "Flapped" NICs. Then reset the nic if link status is down.

.EXAMPLE

ResetHostNics ESXi1

or

Get-VMhost | %{ResetHostNics $_.Name}

.NOTES

By: KnightUSN

################################################################################>

Function ResetHostNics($vhost){

$esxcli = get-vmhost $vhost | Get-EsxCli

$downNics = $esxcli.network.nic.list() | ?{$_.Link -eq "Down"} | select name

ForEach($downNic in $downNics){

Write-Host $vhost " was Affected. Fixing... "$downNic.name

$esxcli.network.nic.down($downNic.Name)

$esxcli.network.nic.up($downNic.Name)

}

}