2009-11-26

Testing Network Failover with PowerCLI

Two weeks ago I wrote an article about How To Bring Down A Single NIC In ESX?. In that post you could see that in order to test this you had to go into the console of the ESX and run the commands on the console.

Already then I was thinking, why not do this from PowerCLI, without having to log into each host.

So here we go..

For the examples sake:

VI Server vcenter.maishsk.local
ESX Host for Testing esx1.maishsk.local
vmnic for Redundancy test vmnic2

 

   1: function Test-NetworkFO ($vmhost, $vmnic, $switch) {
   2:     
   3:     If ($switch){
   4:     ##Define which NIC should be tested   
   5:     $mynic = Get-VMHostNetworkAdapter -VMHost (get-vmhost $vmhost) | `
   6:     Where-Object { $_.DeviceName -eq $vmnic }   
   7:  
   8:     ##Bring the NIC down   
   9:     Set-VMHostNetworkAdapter -PhysicalNic $mynic -Duplex Half -BitRatePerSecMb 10  
  10:     }
  11:     
  12:     If (-not $switch){
  13:     ##Define which NIC should be tested   
  14:     $mynic = Get-VMHostNetworkAdapter -VMHost (get-vmhost $vmhost) | `
  15:     Where-Object { $_.DeviceName -eq $vmnic }   
  16:  
  17:     ##Bring the NIC back up  
  18:     Set-VMHostNetworkAdapter -PhysicalNic $mynic -AutoNegotiate
  19:     }
  20: }
  21:  
  22: # Turn it on
  23: Test-NetworkF0 "vcenter.maishsk.local" "vmnic2" $true
  24:  
  25: # Turn it off
  26: Test-NetworkF0 "vcenter.maishsk.local" "vmnic2" $false


This is a way to test your Network Redundancy for your ESX hosts.

I would like to thank Alan Renouf - who helped me clean up the code and put it into a function.

Have a happy Thanksgiving and a good weekend!