Windows PowerShell Technique: Obtain Network Data

Programming Programming Tips and Tricks Tips-And-Tricks

In order to connect to any local area network (LAN), the first thing every computer requires is the Network Adapter or a Network Interface Card. A network interface card is a computer hardware device that connects a computer to a computer network. Below, we’re going to discover almost all information regarding the connected network adapter; its configuration, status and other properties. This type of information is almost always required by the Network Administrator, in order to monitor and manage the network traffic in the best possible manner.

So let’s move on to sniff out the PowerShell Commandlets which deal with network communication interfaces. First thing first – the basic and the foremost command is Get-NetAdapter. Launch Windows PowerShell and enter this command in the PowerShell console window:


Pretty darn simple – as you can see from the image above, this command provides with some useful information about network adapters, like name, status, mac address and link speed etc.

Let’s see what’s more it provides in conjunction with other cmdlets and parameters.

If you want to obtain information about specific adapters, say Ethernet 2, following command will be helpful:

Get-NetAdapter -Name "ethernet 2"

If you know that you have one or more ethernet interfaces connected to your machine but don’t know their full names, use -like switch with wild card ‘*’:

Get-NetAdapter | where name -like "ethernet*"

The command below produces the same result as the above one:

Get-NetAdapter -Name ethernet*

If you wanna get all properties of Ethernet 2:

Get-NetAdapter -Name "ethernet 2" | Format-List *

To get specific properties (e.g, networkaddresses and macaddress) of Ethernet 2:

Get-NetAdapter -Name "ethernet 2" | select networkaddresses, macaddress

Get network adapters having status as up or running:

Get-NetAdapter | where status -eq "up"

Get those network adapters whose status is not up.

Get-NetAdapter | Where status -ne up

Note that for ‘where’ cmdlet -eq stands for “equal to” and -ne stands for “not equal to”.

To list bound protocols with the network adapters having enabled property to true:

Get-NetAdapter | Get-NetAdapterBinding | ? enabled -eq $true

To obtain list of network adapters which are bound to, e.g, “client for microsoft network” protocole and which are enabled as well:

Get-NetAdapter | Get-NetAdapterBinding | where {$_.enabled -AND $_.displayname -match 'client'}

Get those network adapters whose status is not up and try to enable them (provided that those are connected to the network).

Get-NetAdapter | Where status -ne up | Enable-NetAdapter

Enable adapter whose name starts with “Wi-Fi” e.g, “Wi-Fi 3”

Get-NetAdapter | where name -like "Wi-Fi*" | Enable-NetAdapter

Get those network adapters which status is Up, and then disable them. Also suppress the confirmation prompt which appears after this command, so you don’t have to respond to it.

Get-NetAdapter | ? status -eq up | Disable-NetAdapter -Confirm:$false

Here “?” is equivalent to “where”.

Get Network adapter Power Management settings for the specified adapter.

Get-NetAdapterPowerManagement -Name ethernet*

Leave a Reply

Your email address will not be published. Required fields are marked *