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

NameInterface DescriptionifIndexStatusMacAddressLinkSpeed
Slot 3 Port 2Intel(R) Ethernet Converged Network…#310Not Presentxx-xx-xx-xx-xx-xx0 bps
Slot 5 Port 2Intel(R) Ethernet Converged Network…1Not Presentxx-xx-xx-xx-xx-xx0 bps
NIC TEAMMicrosoft Network Adapter Multiplexer…7Upxx-xx-xx-xx-xx-xx2 Gbps
Slot 6 Port 2Intel(R) Ethernet 10G 2P X550-t Adapter…#217Upxx-xx-xx-xx-xx-xx1 Gbps
Slot 6 Port 1Intel(R) Ethernet 10G 2P X550-t Adapter5Disconnectedxx-xx-xx-xx-xx-xx0 bps
NIC2Intel(R) Ethernet 10G X710 rNDC13Not Presentxx-xx-xx-xx-xx-xx0 bps
Public SecondaryIntel(R) Gigabit 4P X710/I350 rNDC #216Upxx-xx-xx-xx-xx-xx1 Gbps
Public PrimaryIntel(R) Gigabit 4P X710/I350 rNDC9Disconnectedxx-xx-xx-xx-xx-xx0 bps
ISCSI 10.100.0.151 S5P1Intel(R) Ethernet Converged Network…#23Upxx-xx-xx-xx-xx-xx10 Gbps
ISCSI 10.101.0.151 S3P1Intel(R) Ethernet Converged Network…6Upxx-xx-xx-xx-xx-xx10 Gbps
NIC1Intel(R) Ethernet 10G 4P X710/I350 rNDC4Not Presentxx-xx-xx-xx-xx-xx0 bps

narrow it down to just the name

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

NameInterface DescriptionifIndexStatusMacAddressLinkSpeed
NIC TEAMMicrosoft Network Adapter Multiplexer…7Upxx-xx-xx-xx-xx-xx2 Gbps

Get all physical network adapters

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

NameInterface DescriptionifIndexStatusMacAddressLinkSpeed
Slot 6 Port 2Intel(R) Ethernet 10G 2P X550-t Ad…#217Upxx-xx-xx-xx-xx-xx1 Gbps
Slot 6 Port 1Intel(R) Ethernet 10G 2P X550-t Adapter5Disconnectedxx-xx-xx-xx-xx-xx0 bps
Public SecondaryIntel(R) Gigabit 4P X710/I350 rNDC #216Upxx-xx-xx-xx-xx-xx1 Gbps
Public PrimaryIntel(R) Gigabit 4P X710/I350 rNDC9Disconnectedxx-xx-xx-xx-xx-xx0 bps
ISCSI 10.100.0.151 S5P1Intel(R) Ethernet Converged Networ…#23Upxx-xx-xx-xx-xx-xx10 Gbps
ISCSI 10.101.0.151 S3P1Intel(R) Ethernet Converged Network …6Upxx-xx-xx-xx-xx-xx10 Gbps

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

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

NameInterface DescriptionifIndexStatusMacAddressLinkSpeed
Ethernet 3XenServer PV Network Device #03Upxx-xx-xx-xx-xx-xx1 Gbps

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

NameInterface DescriptionifIndexStatusMacAddressLinkSpeedPSComputerName
Slot 3 Port 2Intel(R) Ethernet Converged Networ…#310Not Presentxx-xx-xx-xx-xx-xx0 bpscor-server1
Slot 5 Port 2Intel(R) Ethernet Converged Network …11Not Presentxx-xx-xx-xx-xx-xx0 bpscor-server1
NIC TEAMMicrosoft Network Adapter Multiplexo…7Upxx-xx-xx-xx-xx-xx2 Gbpscor-server1
Slot 6 Port 2Intel(R) Ethernet 10G 2P X550-t Ad…#217Upxx-xx-xx-xx-xx-xx1 Gbpscor-server1
Slot 6 Port 1Intel(R) Ethernet 10G 2P X550-t Adapter5Disconnectedxx-xx-xx-xx-xx-xx0 bpscor-server1
NIC2Intel(R) Ethernet 10G X710 rNDC13Not Presentxx-xx-xx-xx-xx-xx0 bpscor-server1
Public SecondaryIntel(R) Gigabit 4P X710/I350 rNDC #216Upxx-xx-xx-xx-xx-xx1 Gbpscor-server1
Public PrimaryIntel(R) Gigabit 4P X710/I350 rNDC9Disconnectedxx-xx-xx-xx-xx-xx0 bpscor-server1
ISCSI 10.100.0.151 S5P1Intel(R) Ethernet Converged Networ…#23Upxx-xx-xx-xx-xx-xx10 Gbpscor-server1
ISCSI 10.101.0.151 S3P1Intel(R) Ethernet Converged Network …6Upxx-xx-xx-xx-xx-xx10 Gbpscor-server1
NIC1Intel(R) Ethernet 10G 4P X710/I350 rNDC4Not Presentxx-xx-xx-xx-xx-xx0 bpscor-server1

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

NameInterface DescriptionifIndexStatusMacAddressLinkSpeedPSComputerName
Slot 6 Port 2Intel(R) Ethernet 10G 2P X550-t Ad…#217Upxx-xx-xx-xx-xx-xx1 Gbpscor-server1
Slot 6 Port 1Intel(R) Ethernet 10G 2P X550-t Adapter5Disconnectedxx-xx-xx-xx-xx-xx0 bpscor-server1
Public SecondaryIntel(R) Gigabit 4P X710/I350 rNDC #216Upxx-xx-xx-xx-xx-xx1 Gbpscor-server1
Public PrimaryIntel(R) Gigabit 4P X710/I350 rNDC9Disconnectedxx-xx-xx-xx-xx-xx0 bpscor-server1
ISCSI 10.100.0.151 S5P1Intel(R) Ethernet Converged Networ…#23Upxx-xx-xx-xx-xx-xx10 Gbpscor-server1
ISCSI 10.101.0.151 S3P1Intel(R) Ethernet Converged Network …6Upxx-xx-xx-xx-xx-xx10 Gbpscor-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:

NameInterface DescriptionifIndexStatusMacAddressLinkSpeedPSComputerName
Slot 6 Port 2Intel(R) Ethernet 10G 2P X550-t Ad…#217Upxx-xx-xx-xx-xx-xx1 Gbpscor-server1
Public SecondaryIntel(R) Gigabit 4P X710/I350 rNDC #216Upxx-xx-xx-xx-xx-xx1 Gbpscor-server1
ISCSI 10.100.0.151 S5P1Intel(R) Ethernet Converged Networ…#23Upxx-xx-xx-xx-xx-xx10 Gbpscor-server1
ISCSI 10.101.0.151 S3P1Intel(R) Ethernet Converged Network …6Upxx-xx-xx-xx-xx-xx10 Gbpscor-server1

Section 2:

NameInterface DescriptionifIndexStatusMacAddressLinkSpeedPSComputerName
Slot 6 Port 2Intel(R) Ethernet 10G 2P X550-t Ad…#223Upxx-xx-xx-xx-xx-xx1 Gbpscor-server1
Public SecondaryIntel(R) Gigabit 4P X710/I350 rNDC15Upxx-xx-xx-xx-xx-xx1 Gbpscor-server1
Slot 3 Port 2Intel(R) Ethernet Converged Networ…#227Upxx-xx-xx-xx-xx-xx10 Gbpscor-server1
Slot 5 Port 2Intel(R) Ethernet Converged Network …4Upxx-xx-xx-xx-xx-xx10 Gbpscor-server1

Section 3:

NameInterface DescriptionifIndexStatusMacAddressLinkSpeedPSComputerName
Slot 6 Port 2Intel(R) Ethernet 10G 2P X550-t Ad…#223Upxx-xx-xx-xx-xx-xx1 Gbpscor-server1
Public SecondaryIntel(R) Gigabit 4P X710/I350 rNDC15Upxx-xx-xx-xx-xx-xx1 Gbpscor-server1
Slot 3 Port 2Intel(R) Ethernet Converged Networ…#227Upxx-xx-xx-xx-xx-xx10 Gbpscor-server1
Slot 5 Port 2Intel(R) Ethernet Converged Network …4Upxx-xx-xx-xx-xx-xx10 Gbpscor-server1
TEAM1Microsoft Network Adapter Multiplexo…16Upxx-xx-xx-xx-xx-xx1 Gbpscor-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