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:
PS C:\> get-netadapter -CimSession chi-fp02 | Restart-NetAdapter
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.
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
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
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.
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.
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
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.
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.
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.
More in Networking
How to Migrate an Azure ExpressRoute Connection￼
Nov 18, 2022 | Flo Fox
How to Enable AWS Direct Connect Redundancy Using Azure ExpressRoute
Oct 28, 2022 | Flo Fox
Choosing between 2.4 GHz and 5 GHz Wi-Fi
Oct 17, 2022 | Sukesh Mudrakola
Understanding Network Basics: What is TCP, Subnetting, and More
Sep 2, 2022 | Siji Roy
Static vs Dynamic IP Address - What's the Difference?
Mar 29, 2022 | Jason Wynn
What is DNS?
Mar 11, 2022 | Siji Roy
Most popular on petri