PowerShell Script to Get Network Adapter Info
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
How to Think About It
Get-NetAdapter for adapter details and Get-NetIPAddress for IP info. You combine or filter these commands to get exactly what you need.Algorithm
Code
Get-NetAdapter | Select-Object Name, Status, MacAddress | Format-Table -AutoSize
Dry Run
Let's trace the command Get-NetAdapter | Select-Object Name, Status, MacAddress through the code
Get all network adapters
Get-NetAdapter returns a list of adapters with many properties.
Select specific properties
Select-Object picks only Name, Status, and MacAddress from each adapter.
Format output
Format-Table arranges the selected properties in a readable table.
| Name | Status | MacAddress |
|---|---|---|
| Ethernet | Up | 00-1A-2B-3C-4D-5E |
| Wi-Fi | Disconnected | 11-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 | Select-Object InterfaceAlias, IPAddress, AddressFamily
Get-WmiObject -Class Win32_NetworkAdapter | Select-Object Name, NetConnectionStatus, MACAddress
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.
| Approach | Time | Space | Best For |
|---|---|---|---|
| Get-NetAdapter | O(n) | O(n) | Modern, fast adapter info |
| Get-NetIPAddress | O(n) | O(n) | IP address details |
| Get-WmiObject Win32_NetworkAdapter | O(n) | O(n) | Legacy support, detailed info |
Format-Table -AutoSize to make output columns align nicely.