get Network Adapters with PowerShell and PowerCLI

Introduction: get-networkadapter

Network adapters are essential components that enable communication between your computer or virtual machine and the network. In the realm of PowerShell and PowerCLI, the `get-networkadapter` command offers a versatile way to manage and retrieve information about your network adapters. In this post, we’ll delve into the various functionalities and commands associated with network adapters.

 

What does get-NetAdapter do?

The `Get-NetAdapter` cmdlet, available in both PowerShell and PowerCLI, allows you to retrieve detailed information about the network adapters present on your system or within your virtual machines. It provides insights into attributes such as the adapter name, MAC address, link speed, status, and more.

 

How do I find my network adapter?

To identify your network adapter using the Command Prompt (cmd), you can use the `ipconfig` command. This will display a list of network interfaces along with their configurations.

 

How to see network adapter in cmd?

In the Command Prompt, you can use the command `ipconfig /all` to view detailed information about all network interfaces, including their IP addresses, subnet masks, and other pertinent details.

 

How to list network adapter in PowerShell?

Using PowerShell, you can use the `Get-NetAdapter` cmdlet to list all network adapters on your system. Running this command will display a comprehensive list of network adapters with their respective attributes.

PowerShell script to get network adapter information using the Get-NetAdapter cmdlet:

# Gets the basic network adapter properties
$networkAdapters = Get-NetAdapter

foreach ($adapter in $networkAdapters) {
Write-Host "Adapter Name: $($adapter.Name)"
Write-Host "Status: $($adapter.Status)"
Write-Host "MAC Address: $($adapter.MacAddress)"
Write-Host "Link Speed: $($adapter.LinkSpeed) Mbps"
Write-Host "Interface Description: $($adapter.InterfaceDescription)"
Write-Host "Admin Status: $($adapter.AdminStatus)"
Write-Host "Operational Status: $($adapter.OperationalStatus)"
Write-Host "Promiscuous Mode Enabled: $($adapter.PromiscuousMode)"
Write-Host "Media Type: $($adapter.MediaType)"
Write-Host "Connection State: $($adapter.ConnectionState)"
Write-Host "IPv4 Address: $($adapter.IPv4Address.IPAddress)"
Write-Host "IPv4 Subnet Mask: $($adapter.IPv4Address.SubnetMask)"
Write-Host "-----------------------"
}

 

basic network adapter properties

PS C:\> get-netadapter

Name Interface Description ifIndex Status MacAddress LinkSpeed
Slot 3 Port 2 Intel(R) Ethernet Converged Network…#3 10 Not Present xx-xx-xx-xx-xx-xx 0 bps
Slot 5 Port 2 Intel(R) Ethernet Converged Network… 1 Not Present xx-xx-xx-xx-xx-xx 0 bps
NIC TEAM Microsoft Network Adapter Multiplexer… 7 Up xx-xx-xx-xx-xx-xx 2 Gbps
Slot 6 Port 2 Intel(R) Ethernet 10G 2P X550-t Adapter…#2 17 Up xx-xx-xx-xx-xx-xx 1 Gbps
Slot 6 Port 1 Intel(R) Ethernet 10G 2P X550-t Adapter 5 Disconnected xx-xx-xx-xx-xx-xx 0 bps
NIC2 Intel(R) Ethernet 10G X710 rNDC 13 Not Present xx-xx-xx-xx-xx-xx 0 bps
Public Secondary Intel(R) Gigabit 4P X710/I350 rNDC #2 16 Up xx-xx-xx-xx-xx-xx 1 Gbps
Public Primary Intel(R) Gigabit 4P X710/I350 rNDC 9 Disconnected xx-xx-xx-xx-xx-xx 0 bps
ISCSI 10.100.0.151 S5P1 Intel(R) Ethernet Converged Network…#2 3 Up xx-xx-xx-xx-xx-xx 10 Gbps
ISCSI 10.101.0.151 S3P1 Intel(R) Ethernet Converged Network… 6 Up xx-xx-xx-xx-xx-xx 10 Gbps
NIC1 Intel(R) Ethernet 10G 4P X710/I350 rNDC 4 Not Present xx-xx-xx-xx-xx-xx 0 bps

narrow it down to just the name

PS C:\> get-netadapter “NIC TEAM”

Name Interface Description ifIndex Status MacAddress LinkSpeed
NIC TEAM Microsoft Network Adapter Multiplexer… 7 Up xx-xx-xx-xx-xx-xx 2 Gbps

Get all physical network adapters

PS C:\> get-netadapter -Name * -Physical

Name Interface Description ifIndex Status MacAddress LinkSpeed
Slot 6 Port 2 Intel(R) Ethernet 10G 2P X550-t Ad…#2 17 Up xx-xx-xx-xx-xx-xx 1 Gbps
Slot 6 Port 1 Intel(R) Ethernet 10G 2P X550-t Adapter 5 Disconnected xx-xx-xx-xx-xx-xx 0 bps
Public Secondary Intel(R) Gigabit 4P X710/I350 rNDC #2 16 Up xx-xx-xx-xx-xx-xx 1 Gbps
Public Primary Intel(R) Gigabit 4P X710/I350 rNDC 9 Disconnected xx-xx-xx-xx-xx-xx 0 bps
ISCSI 10.100.0.151 S5P1 Intel(R) Ethernet Converged Networ…#2 3 Up xx-xx-xx-xx-xx-xx 10 Gbps
ISCSI 10.101.0.151 S3P1 Intel(R) Ethernet Converged Network … 6 Up xx-xx-xx-xx-xx-xx 10 Gbps

You can also do this to a remote device which is really handy!

PS C:\> Get-NetAdapter -Name * -CimSession “cor-server1”

Name Interface Description ifIndex Status MacAddress LinkSpeed
Ethernet 3 XenServer PV Network Device #0 3 Up xx-xx-xx-xx-xx-xx 1 Gbps

PS C:\> Get-NetAdapter -Name * -CimSession “cor-server1”

Name Interface Description ifIndex Status MacAddress LinkSpeed PSComputerName
Slot 3 Port 2 Intel(R) Ethernet Converged Networ…#3 10 Not Present xx-xx-xx-xx-xx-xx 0 bps cor-server1
Slot 5 Port 2 Intel(R) Ethernet Converged Network … 11 Not Present xx-xx-xx-xx-xx-xx 0 bps cor-server1
NIC TEAM Microsoft Network Adapter Multiplexo… 7 Up xx-xx-xx-xx-xx-xx 2 Gbps cor-server1
Slot 6 Port 2 Intel(R) Ethernet 10G 2P X550-t Ad…#2 17 Up xx-xx-xx-xx-xx-xx 1 Gbps cor-server1
Slot 6 Port 1 Intel(R) Ethernet 10G 2P X550-t Adapter 5 Disconnected xx-xx-xx-xx-xx-xx 0 bps cor-server1
NIC2 Intel(R) Ethernet 10G X710 rNDC 13 Not Present xx-xx-xx-xx-xx-xx 0 bps cor-server1
Public Secondary Intel(R) Gigabit 4P X710/I350 rNDC #2 16 Up xx-xx-xx-xx-xx-xx 1 Gbps cor-server1
Public Primary Intel(R) Gigabit 4P X710/I350 rNDC 9 Disconnected xx-xx-xx-xx-xx-xx 0 bps cor-server1
ISCSI 10.100.0.151 S5P1 Intel(R) Ethernet Converged Networ…#2 3 Up xx-xx-xx-xx-xx-xx 10 Gbps cor-server1
ISCSI 10.101.0.151 S3P1 Intel(R) Ethernet Converged Network … 6 Up xx-xx-xx-xx-xx-xx 10 Gbps cor-server1
NIC1 Intel(R) Ethernet 10G 4P X710/I350 rNDC 4 Not Present xx-xx-xx-xx-xx-xx 0 bps cor-server1

PS C:\> Get-NetAdapter -Name * -Physical  -CimSession “cor-server1”

Name Interface Description ifIndex Status MacAddress LinkSpeed PSComputerName
Slot 6 Port 2 Intel(R) Ethernet 10G 2P X550-t Ad…#2 17 Up xx-xx-xx-xx-xx-xx 1 Gbps cor-server1
Slot 6 Port 1 Intel(R) Ethernet 10G 2P X550-t Adapter 5 Disconnected xx-xx-xx-xx-xx-xx 0 bps cor-server1
Public Secondary Intel(R) Gigabit 4P X710/I350 rNDC #2 16 Up xx-xx-xx-xx-xx-xx 1 Gbps cor-server1
Public Primary Intel(R) Gigabit 4P X710/I350 rNDC 9 Disconnected xx-xx-xx-xx-xx-xx 0 bps cor-server1
ISCSI 10.100.0.151 S5P1 Intel(R) Ethernet Converged Networ…#2 3 Up xx-xx-xx-xx-xx-xx 10 Gbps cor-server1
ISCSI 10.101.0.151 S3P1 Intel(R) Ethernet Converged Network … 6 Up xx-xx-xx-xx-xx-xx 10 Gbps cor-server1

And finally, you can see only the UP interfaces:

PS C:\> Get-NetAdapter -Name * -Physical -CimSession “cor-server1” | where status -eq ‘up’

Section 1:

Name Interface Description ifIndex Status MacAddress LinkSpeed PSComputerName
Slot 6 Port 2 Intel(R) Ethernet 10G 2P X550-t Ad…#2 17 Up xx-xx-xx-xx-xx-xx 1 Gbps cor-server1
Public Secondary Intel(R) Gigabit 4P X710/I350 rNDC #2 16 Up xx-xx-xx-xx-xx-xx 1 Gbps cor-server1
ISCSI 10.100.0.151 S5P1 Intel(R) Ethernet Converged Networ…#2 3 Up xx-xx-xx-xx-xx-xx 10 Gbps cor-server1
ISCSI 10.101.0.151 S3P1 Intel(R) Ethernet Converged Network … 6 Up xx-xx-xx-xx-xx-xx 10 Gbps cor-server1

Section 2:

Name Interface Description ifIndex Status MacAddress LinkSpeed PSComputerName
Slot 6 Port 2 Intel(R) Ethernet 10G 2P X550-t Ad…#2 23 Up xx-xx-xx-xx-xx-xx 1 Gbps cor-server1
Public Secondary Intel(R) Gigabit 4P X710/I350 rNDC 15 Up xx-xx-xx-xx-xx-xx 1 Gbps cor-server1
Slot 3 Port 2 Intel(R) Ethernet Converged Networ…#2 27 Up xx-xx-xx-xx-xx-xx 10 Gbps cor-server1
Slot 5 Port 2 Intel(R) Ethernet Converged Network … 4 Up xx-xx-xx-xx-xx-xx 10 Gbps cor-server1

Section 3:

Name Interface Description ifIndex Status MacAddress LinkSpeed PSComputerName
Slot 6 Port 2 Intel(R) Ethernet 10G 2P X550-t Ad…#2 23 Up xx-xx-xx-xx-xx-xx 1 Gbps cor-server1
Public Secondary Intel(R) Gigabit 4P X710/I350 rNDC 15 Up xx-xx-xx-xx-xx-xx 1 Gbps cor-server1
Slot 3 Port 2 Intel(R) Ethernet Converged Networ…#2 27 Up xx-xx-xx-xx-xx-xx 10 Gbps cor-server1
Slot 5 Port 2 Intel(R) Ethernet Converged Network … 4 Up xx-xx-xx-xx-xx-xx 10 Gbps cor-server1
TEAM1 Microsoft Network Adapter Multiplexo… 16 Up xx-xx-xx-xx-xx-xx 1 Gbps cor-server1

PowerCLI: Retrieving VM Network Information

When working with virtual machines, you can leverage PowerCLI commands to retrieve network-related information. The `Get-VMNetworkAdapter` cmdlet provides details about network adapters associated with virtual machines.

 

Exploring get-VMNetworkAdapter

The `Get-VMNetworkAdapter` cmdlet in PowerCLI offers insights into the network adapters of virtual machines. This information includes adapter type, MAC address, network name, connection state, and more.

 

Understanding get-VdPortgroup

In VMware environments, the `Get-VdPortgroup` cmdlet allows you to obtain information about distributed port groups, aiding in network management and configuration.

 

PowerCLI: Get-VM Network Name

Using PowerCLI, the `Get-VM` cmdlet can help you retrieve the network name associated with a virtual machine, enhancing your understanding of its network configuration.

 

PowerCLI: Get VM Network Adapter Type

With the `Get-VMNetworkAdapter` cmdlet, you can ascertain the type of network adapter associated with a virtual machine. This is particularly useful for assessing network performance and compatibility.

 

Modifying Network Adapters with PowerCLI

PowerCLI provides the `Set-NetworkAdapter` cmdlet, enabling you to modify various attributes of a network adapter. This includes settings such as the adapter’s MAC address, network name, and connection state.

 

Configuring Port Groups with set-NetworkAdapter

When working with virtualization platforms like VMware, the `Set-NetworkAdapter` cmdlet allows you to configure network adapter settings, such as associating a specific port group with a virtual machine.

 

PowerCLI: Disconnect Network Adapter

At times, you may need to disconnect a network adapter from a virtual machine. PowerCLI facilitates this process through the `Disconnect-NetworkAdapter` cmdlet, aiding in maintenance or troubleshooting scenarios.

 

Leave a Comment