Skip to content

Get-HostNetworkAdapter

VMware: Retrieves the host network adapters on a vCenter Server system

#Requires -Version 5.1
#Requires -Modules VMware.VimAutomation.Core
[CmdletBinding()]
Param(
    [Parameter(Mandatory = $true)]
    [string]$VIServer,
    [Parameter(Mandatory = $true)]
    [pscredential]$VICredential,
    [string]$HostName,
    [switch]$Console,
    [switch]$Physical,
    [switch]$VMKernel,
    [string]$AdapterName,
    [string]$PortGroupName
)
Process {
    $vmServer = $null
    try {
        if ([System.String]::IsNullOrWhiteSpace($HostName)) { $HostName = "*" }
        if ([System.String]::IsNullOrWhiteSpace($AdapterName)) { $AdapterName = "*" }
        if ([System.String]::IsNullOrWhiteSpace($PortGroupName)) { $PortGroupName = "*" }
        $vmServer = Connect-VIServer -Server $VIServer -Credential $VICredential -ErrorAction Stop
        $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
        $result = Get-VMHostNetworkAdapter -Server $vmServer -Console:$Console -Physical:$Physical -VMKernel:$VMKernel -Name $AdapterName -PortGroup $PortGroupName -VMHost $HostName -ErrorAction Stop | Select-Object *
        foreach ($item in $result) {
            $item | Add-Member -NotePropertyName 'Timestamp' -NotePropertyValue $timestamp -Force
            Write-Output $item
        }
    }
    catch { throw }
    finally { if ($null -ne $vmServer) { Disconnect-VIServer -Server $vmServer -Force -Confirm:$false -ErrorAction SilentlyContinue } }
}

IP address or DNS name of the vSphere server

PSCredential object for authenticating with the server

Host whose network adapters to retrieve; retrieves all if empty

Off

Retrieve only service console virtual network adapters

Off

Retrieve only physical network adapters

Off

Retrieve only VMKernel virtual network adapters

Name of the host network adapter to retrieve

Name of the port group to filter by

An interactive directory of PowerShell scripts.