ErrorAction for Get-VMHostNetworkAdapter broken

The ErrorAction parameter still throws an error even if the “SilentlyContinue” option is selected. This is a problem if you just want to check the existence of NICs on a ESX Host.

$ESXHost = Get-VMHost esx.fqdn -ErrorAction:Stop
$dvSwitch = Get-VDSwitch -Name dvSwitch1 -Location virtualDatacenter -VMHost $ESXHost -ErrorAction:Stop
$Portgroup = Get-VDPortgroup -Name Management Network -VDSwitch $dvSwitch -ErrorAction:Stop
Get-VMHostNetworkAdapter -VMHost $ESXHost -VMKernel:$true -VirtualSwitch $dvSwitch -PortGroup $Portgroup -ErrorAction:SilentlyContinue | out-null

If the Host has no vmk NIC configured on the “Management Network” portgroup of dvSwitch1 the CMDlet still throws a error message. My workaround is a empty try/catch function to suppress the error message.

try {
    Get-VMHostNetworkAdapter -VMHost $ESXHost -VMKernel:$true -VirtualSwitch $dvSwitch -PortGroup $Portgroup -ErrorAction:SilentlyContinue | out-null
catch {

Also for this bug a VMware SR is open. Let’s see if this bug is fixed in the next PowerCLI version.

The VMware versions in my development environment.

PowerCLI Version
VMware vSphere PowerCLI 5.5 Release 2 Patch 1 build 1931983
Snapin Versions
VMWare AutoDeploy PowerCLI Component 5.5 build 1890764
VMWare ImageBuilder PowerCLI Component 5.5 build 1890764
VMware vCloud Director PowerCLI Component 5.5 build 1649227
VMware License PowerCLI Component 5.5 build 1265954
VMware VDS PowerCLI Component 5.5 build 1926677
VMware vSphere PowerCLI Component 5.5 Patch 1 build 1926677
VMware vSphere Update Manager PowerCLI 5.5 build 1302474
vSphere Versions
vCenter 5.5 1891313
ESX 5.5 1331820