0
0
PowershellHow-ToBeginner · 2 min read

PowerShell Script to Get Network Adapter Info

Use the PowerShell command Get-NetAdapter to get basic network adapter info or Get-NetIPAddress to see IP details; for a combined view, run Get-NetAdapter | Select-Object Name, Status, MacAddress.
📋

Examples

InputGet-NetAdapter | Select-Object Name, Status
OutputName Status ---- ------ Ethernet Up Wi-Fi Disconnected
InputGet-NetIPAddress -InterfaceAlias Ethernet
OutputIPAddress : 192.168.1.10 InterfaceAlias : Ethernet AddressFamily : IPv4 PrefixLength : 24 Type : Unicast
InputGet-NetAdapter | Select-Object Name, Status, MacAddress
OutputName Status MacAddress ---- ------ ---------- Ethernet Up 00-1A-2B-3C-4D-5E Wi-Fi Disconnected 11-22-33-44-55-66
🧠

How to Think About It

To get network adapter info, think about what details you want: name, status, IP, or MAC address. PowerShell has built-in commands like Get-NetAdapter for adapter details and Get-NetIPAddress for IP info. You combine or filter these commands to get exactly what you need.
📐

Algorithm

1
Run the command to list all network adapters.
2
Select the properties you want to see, like Name, Status, and MacAddress.
3
Optionally, get IP address info for each adapter.
4
Display the collected information to the user.
💻

Code

powershell
Get-NetAdapter | Select-Object Name, Status, MacAddress | Format-Table -AutoSize
Output
Name Status MacAddress ---- ------ ---------- Ethernet Up 00-1A-2B-3C-4D-5E Wi-Fi Disconnected 11-22-33-44-55-66
🔍

Dry Run

Let's trace the command Get-NetAdapter | Select-Object Name, Status, MacAddress through the code

1

Get all network adapters

Get-NetAdapter returns a list of adapters with many properties.

2

Select specific properties

Select-Object picks only Name, Status, and MacAddress from each adapter.

3

Format output

Format-Table arranges the selected properties in a readable table.

NameStatusMacAddress
EthernetUp00-1A-2B-3C-4D-5E
Wi-FiDisconnected11-22-33-44-55-66
💡

Why This Works

Step 1: Get-NetAdapter command

The Get-NetAdapter command fetches all network adapters on your computer with detailed info.

Step 2: Selecting properties

Using Select-Object lets you pick only the important details like Name, Status, and MacAddress to keep output simple.

Step 3: Formatting output

The Format-Table command arranges the data neatly in columns so it’s easy to read.

🔄

Alternative Approaches

Get-NetIPAddress for IP details
powershell
Get-NetIPAddress | Select-Object InterfaceAlias, IPAddress, AddressFamily
Shows IP addresses linked to each network adapter but does not show adapter status or MAC address.
Using WMI with Get-WmiObject
powershell
Get-WmiObject -Class Win32_NetworkAdapter | Select-Object Name, NetConnectionStatus, MACAddress
Works on older Windows versions but is slower and less modern than Get-NetAdapter.

Complexity: O(n) time, O(n) space

Time Complexity

The commands iterate over each network adapter once, so time grows linearly with the number of adapters.

Space Complexity

Memory usage grows linearly with the number of adapters because all adapter info is stored before output.

Which Approach is Fastest?

Using Get-NetAdapter is faster and more efficient than WMI commands, which are slower and more resource-heavy.

ApproachTimeSpaceBest For
Get-NetAdapterO(n)O(n)Modern, fast adapter info
Get-NetIPAddressO(n)O(n)IP address details
Get-WmiObject Win32_NetworkAdapterO(n)O(n)Legacy support, detailed info
💡
Use Format-Table -AutoSize to make output columns align nicely.
⚠️
Beginners often forget to select specific properties and get overwhelmed by too much raw data.