Petri

Manage Network Adapters with PowerShell

For IT pros, the name of the game is management, and the easier the better. For most of us this means Windows PowerShell. And when we throw Windows Server 2012 into the mix it gets even better. Windows 8 and Windows include a number of new modules specifically designed to manager network adapters, configuration, and security. These modules are based on the new CIM infrastructure that is part of Windows Management Framework 3. However, even if you have PowerShell 3 installed on, say, Windows Server 2008 R2, you don’t get these new toys. The underlying CIM namespaces and classes only exist on Windows 8 and Windows Server 2012. However, if you have a Windows 8 admin desktop and some Windows Server 2012 boxes, you’ll be amazed what you can accomplish.

Sponsored

This is part one of a three-part series. Today I’ll talk about how to get a network adapter with PowerShell and getting network adapter statistics. In part two, I’ll go into addressing and configuration information. Finally, in part three I’ll explore PowerShell cmdlets that might come in handy when troubleshooting a networking issue.

Getting Network Adapters

Enumerating network adapters couldn’t be easier. In PowerShell 3 you don’t even need to import the module first. Simply type the command. Here’s how I can get the network adapters on my laptop:

As you can see in below in Figure 1, I have a lot going on.

Windows 8 Network Adapters

You can narrow down results by name:

Or by interface description:

Or you can limit your query to physical adapters only.

My results can be seen in the image below.

Network Adapter Options

 

You can also query a remote computer via a CIM session, although all you need to do is specify a computer name.

As you can see in Figure 3, there’s much more information available.

Querying a remote network adapter

 

Sponsored

If you think you’ll be working with a remote computer more than once, then it is worth the short amount of time it takes to create a CIMSession. I’m going to jump into my domain and do just that. Here’s the command I’ll run on my Windows 8 client, logged on with an account that has admin rights on the remote computers. (Although New-CimSession supports alternate credentials anyway.)

I can use this collection of CIM Sessions with Get-NetAdapter.

The default output from Get-NetAdapter doesn’t include the computer name, and obviously I need to be able to tell what adapter goes with what computer. Since I was at it, I grabbed a few other parameters as well. I piped to Out-Gridview to make it easier to see and work with the results.

Remote Network Adapter Details

Adapter Advanced Properties

We can also discover advanced properties for the network adapter. Here’s a basic command on a system that only has a single adapter.

Advanced Adapter Properties

 

This also works remotely, and you can limit the properties.

Advanced Adapter Properties from remote computers

Sponsored

Getting Network Adapter Statistics

Lastly, let me show you how easy it is to get adapter statistics. First, let’s explore the local adapter.

As you can see below in Figure 7, there is even more data available than what I’ve shown above.

PS-NIC-1-Fig7

It doesn’t take much to convert byte values to MB.

Or query remote machines, as I did in Figure 8.

Remote adapter statistics

It wasn’t intentional, but there was an interruption querying one of the servers. But because I used a CIM session, one of its benefits is resilience. The session retried and eventually reconnected and retrieved the data. Let me leave you with one more example.

Here I have an interactive GUI to analyze network statistics from my servers.

Complete adapter statistics

At no time did I have to resort to any type of scripting. I merely ran cmdlets in an interactive session.

We’ve just started to scratch the surface of what we can accomplish with PowerShell and Windows Server 2012. We’ll continue the exploration in the next article. In the meantime, take a look at full help and examples for all of the cmdlets I used and start trying them out in your own test environment.

Tagged , ,

Sponsored

Join The Conversation

Sponsors

Sponsors