PowerShell Pipeline
Use PowerShell To Work with a Network Adapter
If PowerShell isn't already your go-to tool for reviewing your NIC configuration, it should be.
In the past, we had to use various means to understand how our network interface card (NIC) was configured, as well as see what IP address was assigned to it.
Whether it was going through the GUI to look at the properties of the NIC or using our faithful command ipconfig to look at not only the IP address, but also other things such as the DNS settings or default gateway, these are some of the most important areas that we might look at when troubleshooting some sort of networking issue.
As with a lot of things using PowerShell, we were able to begin to look at automating things like reporting on all of the settings within a NIC using WMI, such as the Win32_NetworkAdapter class, which provided a great window into many things on the NIC.
PS C:\> (Get-WmiObject -Class Win32_NetworkAdapterConfiguration).Where{$_.IPAddress}|Format-List
DHCPEnabled : True
IPAddress : {192.168.1.171}
DefaultIPGateway : {192.168.1.1}
DNSDomain :
ServiceName : VMSMP
Description : Hyper-V Virtual Ethernet Adapter
Index : 4
DHCPEnabled : True
IPAddress : {169.254.68.58}
DefaultIPGateway :
DNSDomain :
ServiceName : VMSMP
Description : Hyper-V Virtual Ethernet Adapter #2
Index : 5
DHCPEnabled : True
IPAddress : {192.168.186.65, fe80::157e:349d:dc91:95c5}
DefaultIPGateway :
DNSDomain :
ServiceName : VMSMP
Description : Hyper-V Virtual Ethernet Adapter #3
Index : 11
Using Get-NetIPConfiguration, we can grab most of the same information that is the same WMI class.
PS C:\> Get-NetIPConfiguration
InterfaceAlias : vEthernet (External)
InterfaceIndex : 18
InterfaceDescription : Hyper-V Virtual Ethernet Adapter
NetProfile.Name : Alpha1_5G
IPv4Address : 192.168.1.171
IPv4DefaultGateway : 192.168.1.1
DNSServer : 192.168.1.1
InterfaceAlias : vEthernet (Default Switch)
InterfaceIndex : 22
InterfaceDescription : Hyper-V Virtual Ethernet Adapter #3
NetProfile.Name : Unidentified network
IPv4Address : 192.168.186.65
IPv6DefaultGateway :
IPv4DefaultGateway :
DNSServer : fec0:0:0:ffff::1
fec0:0:0:ffff::2
fec0:0:0:ffff::3
InterfaceAlias : vEthernet (Internal)
InterfaceIndex : 8
InterfaceDescription : Hyper-V Virtual Ethernet Adapter #2
NetProfile.Name : Unidentified network
IPv4Address : 169.254.68.58
IPv4DefaultGateway :
DNSServer :
Now, you could continue to use WMI to gather this information, but this is yet another path to take if you are looking to gather information on systems locally or remotely.
Using Get-NetAdapter, you can also view more information about all of your adapters or a single one.
PS C:\> Get-NetAdapter
Name InterfaceDescription ifIndex Status MacAddress LinkSpeed
---- -------------------- ------- ------ ---------- ---------
vEthernet (Default Swi... Hyper-V Virtual Ethernet Adapter #3 22 Up 96-15-63-AD-B0-CD 10 Gbps
vEthernet (Internal) Hyper-V Virtual Ethernet Adapter #2 8 Up 00-15-5D-01-AB-01 10 Gbps
vEthernet (External) Hyper-V Virtual Ethernet Adapter 18 Up 18-4F-32-F7-8F-4F 600 Mbps
Wi-Fi Dell Wireless 1830 802.11ac 12 Up 18-4F-32-F7-8F-4F 600 Mbps
Ethernet 2 Microsoft Network Adapter Multiplexo... 24 Up 18-4F-32-F7-8F-4F 600 Mbps
PS C:\> Get-NetAdapter -InterfaceIndex 12 |Format-List
Name : Wi-Fi
InterfaceDescription : Dell Wireless 1830 802.11ac
InterfaceIndex : 12
MacAddress : 18-4F-32-F7-8F-4F
MediaType : 802.3
PhysicalMediaType : Native 802.11
InterfaceOperationalStatus : Up
AdminStatus : Up
LinkSpeed(Mbps) : 600
MediaConnectionState : Connected
ConnectorPresent : True
DriverInformation : Driver Date 2017-10-18 Version 1.566.0.2 NDIS 6.50
If I wanted to enable or disable an adapter, I can pipe the object (or objects) from Get-NetAdapter and send to Disable/Enable-Adapter and disable/enable a single adapter or multiple. Note in the following examples that I choose to use -WhatIf to only simulate what would happen if the command were to run.
PS C:\> Get-NetAdapter | Disable-NetAdapter -WhatIf
What if: Disable-NetAdapter 'Ethernet 2'
What if: Disable-NetAdapter 'vEthernet (Internal)'
What if: Disable-NetAdapter 'vEthernet (Default Switch)'
What if: Disable-NetAdapter 'Wi-Fi'
What if: Disable-NetAdapter 'vEthernet (External)'
If you wanted to start looking around and even possibly configuring some of the advanced properties of a particular adapter, all of that can be done via PowerShell and the Get/Set-NetAdapterAdvancedConfiguration cmdlets.
PS C:\> Get-NetAdapter -InterfaceIndex 12 | Get-NetAdapterAdvancedProperty
Name DisplayName DisplayValue RegistryKeyword RegistryValue
---- ----------- ------------ --------------- -------------
Wi-Fi Packet Coalescing Enabled *PacketCoale... {1}
Wi-Fi ARP Offload Enabled *PMARPOffload {1}
Wi-Fi NS Offload Enabled *PMNSOffload {1}
Wi-Fi WiFi Rekeying Offload Enabled *PMWiFiRekey... {1}
Wi-Fi Priority & VLAN Priority & VLAN Disabled *PriorityVLA... {0}
Wi-Fi Wake On Magic Packet Enabled *WakeOnMagic... {1}
Wi-Fi Wake On Pattern Match Enabled *WakeOnPattern {1}
Wi-Fi Antenna Diversity Auto antdiv {-1}
Wi-Fi 802.11d Support (Auto-Country) Enabled autoCountryD... {1}
Wi-Fi Bluetooth Collaboration Auto BTCoexist {3}
Wi-Fi 2G Bandwidth Capability 2.4G: 20MHz BWCap2G {0}
Wi-Fi D2 Listen Interval 5 D2ListenInte... {5}
Wi-Fi Enable/Disable LTR Enabled EnableLTR {1}
Wi-Fi Fragmentation Threshold 2346 frag {2346}
Wi-Fi XPress (TM) Technology Enabled FrameBursting {1}
Wi-Fi 40MHz Intolerant Disabled Intolerant {0}
Wi-Fi Assoc Listen Interval 1 ListenInterval {1}
Wi-Fi LTR Active value in microse... 60 LTR_ActiveValue {60}
Wi-Fi Minimum Power Consumption Enabled MPC {1}
Wi-Fi Locally Administered MAC Ad... -- NetworkAddress {--}
Wi-Fi 20/40 Coexistance Auto OBSSCoex {-1}
Wi-Fi BSS PLCP Header Auto (Short/Long) PLCPHeader {0}
Wi-Fi Power Output 75% PwrOut {75}
Wi-Fi RTS Threshold 2347 rts {2347}
Wi-Fi WFD Channel Number 11 WFDChannelNu... {11}
Wi-Fi WMM Auto WME {-1}
Let's say that I wanted to disable the wake on magic packet setting on an adapter. I would use Set-NetAdapterAdvancedConfiguration to accomplish this. I would not pipe the object from Get-NetAdapter and instead would use the parameter names to fill in the blanks. This includes having to type out the InterfaceDescription of the network adapter.
PS C:\> Set-NetAdapterAdvancedProperty -InterfaceDescription 'Dell Wireless 1830 802.11ac' -DisplayName 'Wake On
acket' -DisplayValue 'Disabled' -WhatIf
What if: Set-NetAdapterAdvancedProperty 'Wi-Fi' -DisplayName 'Wake On Magic Packet' -DisplayValue 'Disabled'
For the sake of not breaking something, I went ahead and used -WhatIf again.
With some of these examples, you can see how PowerShell is now your go-to tool for reviewing your NIC configuration, as well as for being able to make changes to any adapter that you have on your system.
About the Author
Boe Prox is a Microsoft MVP in Windows PowerShell and a Senior Windows System Administrator. He has worked in the IT field since 2003, and he supports a variety of different platforms. He is a contributing author in PowerShell Deep Dives with chapters about WSUS and TCP communication. He is a moderator on the Hey, Scripting Guy! forum, and he has been a judge for the Scripting Games. He has presented talks on the topics of WSUS and PowerShell as well as runspaces to PowerShell user groups. He is an Honorary Scripting Guy, and he has submitted a number of posts as a to Microsoft's Hey, Scripting Guy! He also has a number of open source projects available on Codeplex and GitHub. His personal blog is at http://learn-powershell.net.