Coming Soon: GET:IT Endpoint Management 1-Day Conference on September 28th at 9:30 AM ET Coming Soon: GET:IT Endpoint Management 1-Day Conference on September 28th at 9:30 AM ET
Networking

Manage Network Adapters with PowerShell: Configure an Adapter

Over my last few articles I’ve been demonstrating how to use PowerShell to manage network adapters in Windows Server 2012 (and since the code base is the same – though to a lesser degree – Windows 8 adapters as well). To this point I’ve shown you how to gather a lot of information. In this article let’s start on how to configure an adapter. I hope it goes without saying, but don’t forget that some changes might not take effect until we restart the adapter, and network connections could be interrupted. So test everything in a non-production environment first.

This is part four of a multi-part series. I’ve already covered how to manage network adapters with PowerShell and how to configure network adapters in Windows Server 2012. And in part three, I went over how to troubleshoot some networking issues using PowerShell cmdlets.

Manage Network Adapters with PowerShell: Using Set-NetAdapter

The Set-NetAdapter cmdlet is part of the NetAdapter module. You can specify an adapter by name, interface description, or pipe an adapter from Get-NetAdapter. You primarily can use this cmdlet to set the adapter’s VLAN ID (if supported) or the MAC address. The cmdlet even supports –WhatIf

​ PS C:\> get-netadapter -CimSession chi-fp02 | Set-NetAdapter -MacAddress "001122334455" -whatif

What if: chi-fp02: Set-NetAdapter 'Ethernet' -MacAddress 001122334455

I ran this command from my Windows 8 admin desktop. The remote adapter will most likely automatically restart when you make a change. But you can include –NoRestart to defer this operation. If you need to manually restart the adapter, use a command like this:

Sponsored Content

Say Goodbye to Traditional PC Lifecycle Management

Traditional IT tools, including Microsoft SCCM, Ghost Solution Suite, and KACE, often require considerable custom configurations by T3 technicians (an expensive and often elusive IT resource) to enable management of a hybrid onsite + remote workforce. In many cases, even with the best resources, organizations are finding that these on-premise tools simply cannot support remote endpoints consistently and reliably due to infrastructure limitations.

​ PS C:\> get-netadapter -CimSession chi-fp02 | Restart-NetAdapter

As you can see in Figure 1 below, this kills the network connection, but PowerShell 3.0 attempts to re-establish it.

manage network adapter with PowerShell: setadapter

It is also possible to completely disable and enable network adapters.

​ PS C:\> get-netadapter -CimSession chi-fp02 | Disable-NetAdapter

You’ll be prompted for confirmation. As before, PowerShell will attempt to reconnect, but since the remote adapter is offline, this should eventually fail.

manage network adapter with PowerShell: setadapter

Of course, I’ll have to be on the remote computer to re-enable it if there is only a single adapter.

​ PS C:\> Enable-Netadapter –name Ethernet

Set-NetAdapterAdvancedProperty

I would expect advanced properties to fall under the special exception category. Using Set-NetAdapterAdvancedProperty you should be able to set any of the settings you see in Figure 3.

​ PS C:\> Get-NetAdapterAdvancedProperty -CimSession chi-fp02

manage network adapter with PowerShell: Set-NetAdapterAdvancedProperty

For example, let’s say I want to enable support for jumbo packets on the adapter in CHI-FP02. I can use a command like this:

​ PS C:\> Set-NetAdapterAdvancedProperty -CimSession chi-fp02 -DisplayName "Jumbo*" -DisplayValue "9014 bytes" –PassThru

Because the server only has a single adapter, this command should work just fine. Otherwise I would need to come up with a query using Get-NetAdapter or use the –Name property from Set-NetAdapterAdvancedProperty to set the correct one. And here’s a tip: If you aren’t sure what the correct value is for the display value, use a bogus value like FOO and the exception message should indicate the acceptable values. You can see my results in Figure 4.

manage network adapter with PowerShell: Set-NetAdapterAdvancedProperty

And of course what I can do for one I can do for many, as long as the remote computers are running Windows Server 20121 or later. Figure 5 shows the Jumbo Packet settings for a few computers.

manage network adapter with PowerShell: Set-NetAdapterAdvancedProperty

Now I can modify the setting on all of them with a single command.

​ PS C:\> get-netadapter -CimSession chi-fp02,chi-app01,chi-dev01 | set-NetAdapterAdvancedProperty -DisplayName "Jumbo*" -displayvalue "4088 bytes" -passthru | select PSComputername,Displayname,Displayvalue

This may take a little time to complete as the adapter is getting reset on each computer. Or I could have used –NoRestart. My results can be seen in Figure 6.

manage network adapter with PowerShell: setadapter

Set-NetAdapterBinding

The last item you might need to set is adapter binding. By that I mean protocols and services like QoS, File and Print Sharing, and IPv6. You can see them with Get-NetAdapterBinding. Figure 7 displays some settings on a few servers that I want to change.

manage network adapter with PowerShell: Set-NetAdapterBinding

I can disable these with Set-NetAdapterBinding.

​ PS C:\> get-netadapterbinding -CimSession chi-fp02,chi-app01,chi-dev01 -ComponentID ms_pacer,ms_tcpip6| Set-Netadapterbinding -Enabled $false -PassThru | select PSComputername,Displayname,Enabled

Just like that, these bindings have been disabled as you see in Figure 8.

manage network adapter with PowerShell: Set-NetAdapterBinding

Seriously, I don’t see how this could get any easier.

What I’ve shown you is by no means all that you can do with these cmdlets. As with all PowerShell articles, be sure to read full help and examples. In the next article we’ll look at some additional configuration options.

Related Topics: