Finding NICs That Aren’t VMXNET3

Earlier this week, someone on our team received a request to change a VMware virtual machine’s NIC from e1000 to VMXNET3. While the change was a bit manual in nature due to the Guest OS configuration changes, it got us thinking… How many other VM’s might still have e1000 NIC adapters? So, I started working on a script to find out.

Initially, the script was built to only look for e1000 NIC adapters in a cluster. However, it didn’t take very long to realize that we were missing the e1000e NIC. At this point, I also remembered that there were other NIC types that could exist in the environment, such as Flexible, VMXNET, and VMXNET2. So instead of only looking for e100* NICs ( Where-Object {$_.type -eq ‘e100*’} ), I changed it to look for anything that’s not VMXNET3 by using ( Where-Object {$_.type -ne ‘vmxnet3’} ) instead.

Here’s the script (also available on my GitHub page):

##################################################
# Script: find-other-nics-in-a-cluster.ps1
# Author: Doug DeFrank
# Date: 2017-12-27
#
# Purpose: Find non-VMXNET3 adapters in a VMware Cluster
##################################################

### Initialize array(s)
$report = @()

$date = Get-Date -format "yyyyMMdd"

Write-Host "This script will find all VM's that have e1000, e1000e, or other non-VMXNET3 adapters in a given cluster." `n

### Prompt the user for vCenter Server name, and connect to it.
$vCenterServer = Read-Host -Prompt 'Enter the FQDN of the vCenter Server you want to connect to. (ex. vcenter.domain.com)'
Connect-VIServer -Server $vCenterServer -WarningAction SiletlyContinue | Out-Null

### Prompt the user for the cluster name within that vCenter Server
$ClusterName = Read-Host -Prompt 'Enter the full name of the cluster you want to work with (ex. Prod-Cluster-01)'

### Get information about all VMs in the defined cluster
$VMs = Get-Cluster -Name $ClusterName | Get-VM | Sort-Object

### Find VMs where an associated network adapter isn't a VMXNET3 NIC
$NotVmxnet3 = $VMs | Get-NetworkAdapter | Where-Object {$_.type -ne 'vmxnet3'} 

foreach ($vm in $NotVmxnet3) {
$row = "" | Select-Object VMName,NICAdapter,NetworkName,AdapterType
$row.VMName = $vm.Parent
$row.NICAdapter = $vm.Name
$row.NetworkName = $vm.NetworkName
$row.AdapterType = $vm.Type

### Build the report
$report += $row
}

### If the report is empty, notify the user that no non-VMXNET3 NICs were detected.
If (!$report) {
Write-Host -ForegroundColor Yellow "There were no non-VMXNET3 NICs detected in the cluster $ClusterName" `n
}

### Display the report results
Else {

### Ask the user if they want to generate a CSV file of the results
Do {
Write-Host `n "Do you want to export the results to a CSV file?"
Write-Host "1.) Yes"
Write-Host "2.) No"
$Choice = Read-Host
Switch ($Choice) {

### If the user answers 1 (Yes), generate a CSV file
1 {
Write-Host "Generating a CSV report in the same directory as this PowerCLI script."
$report | Export-CSV ".\NIC-Report-for-$ClusterName-$date.csv" -NoTypeInformation
$cont = $true
}

### If the user answers 2 (No), do nothing
2 { $cont = $true}

### Validate that the user input is either a 1 or a 2. Otherwise, ask the question again.
default {
$cont = $false
Write-Host -ForegroundColor Red ">>> Invalid input. Please answer [1] for Yes or [2] for No."
}
}
}

### Repeat the question until valid input is received
Until ($cont)
}

### Disconnect from the vCenter Server
Disconnect-VIServer -Server $vCenterServer -confirm:$false | Out-Null

This script can also be modified to scan an entire datacenter instead of a cluster. Simply swap out Get-Cluster with Get-Datacenter and rename $ClusterName to $DatacenterName (to avoid possible confusion) and that should do it!

As always, thank you for stopping by! I hope this script helps you locate the various e1000 and other non-VMXNET3 adapters that may be lurking in your environment.

Advertisements

2 thoughts on “Finding NICs That Aren’t VMXNET3”

  1. I just dealt with converting a NIC from e1000e to VMXNET 3 last week, and have another one in my future. Thanks for sharing this script! I’ll definitely use it (or a variant of it) to identify if we have others that should be changed.

    Thanks!

    Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s