- Recommended security settings and new group policies for Microsoft Edge (from 107 on) - Fri, Jan 27 2023
- Save and access the BitLocker recovery key in the Microsoft account - Tue, Jan 24 2023
- Reopen apps after Windows startup - Thu, Jan 19 2023
On a workstation, you usually access the network adapter settings through the GUI where you can also change properties. However, on Server Core or Nano Server you have to rely on the command line. In addition to the netsh.exe tool, PowerShell is often the best choice – also because you can manage network interfaces remotely.
Reading the configuration with Get-NetAdapter
If you want to get an overview of the available NICs and their statuses, Get-NetAdapter offers the most important information. If you run the cmdlet without arguments, it reads all adapters and displays a few of their properties such as the MAC address, the status, and the link speed.
However, Get-NetAdapter can retrieve more than 100 properties that you can display with the help of Get-Member:
Get-NetAdapter -Name Ethernet0 | Get-Member -MemberType Property
This command only retrieves information from one interface to avoid displaying properties multiple times. The Name parameter also accepts wildcards, which allows you to access all interfaces that begin with "Ethernet":
Get-NetAdapter -Name Ethernet*
Alternatively, you can use the parameter InterfaceDescription and InterfaceIndex to filter the output:
Get-NetAdapter -InterfaceDescription Real*
Respectively:
Get-NetAdapter -InterfaceIndex 3
Once you have found the required properties of the MSFT_NetAdapter object using Get-Member, you can extract them as usual with Select-Object.
Get-NetAdapter -Name vEth* | select Name, MacAddress, MediaConnectionState, MediaType
You can get some of the attributes by using the parameters of Get-NetAdapter as filters, for instance to access only one physical adapter:
Get-NetAdapter -Physical
However, if you only want to retrieve virtual adapters, you again will need Select-Object:
Get-NetAdapter | ? Virtual -eq $true
You can list all interface properties with Format-List and the parameter Property.
Get-NetAdapter -Name vEth* | Format-List -Property
Additional attributes with Get-NetAdapterAdvancedProperty
However, even with this command, some attributes are still hidden, for example those for offloading various operations, the configuration of jumbo frames, or Wake-On-LAN. To read those properties, you need additional cmdlets such as Get-NetAdapterAdvancedProperty and Get-NetAdapterPowerManagement.
You can filter the adapter properties with these two cmdlets in the same way as with Get-NetAdapter by using the parameters Name and InterfaceDescription. Selecting the attributes works accordingly.
Configuring Wake-on-LAN
For example, if you want to read the Wake-On-LAN (WOL) settings on all physical interfaces whose names begin with "Eth," you can use this command:
Get-NetAdapter -Physical -Name Eth* | Get-NetAdapterPowerManagement | select Name, WakeOnMagicPacket
If you want to enable WOL on all those adapters, Set-NetAdapterPowerManagement will do the job:
Set-NetAdapterPowerManagement -Name Eth* -WakeOnMagicPacket Enabled
Displaying bound protocols
If you require information about the protocols that are bound to certain adapters, you can work with Get-NetAdapterBinding:
Get-NetAdapterBinding -Name Eth* -AllBindings
This example will display all protocols that are bound to the adapter whose names begin with "Eth*."
For example, if you want to retrieve the interfaces where IPv4 is not activated, then this commands helps:
Get-NetAdapterBinding -Name * | ? {$_.ComponentID -eq "ms_tcpip" -and $_.Enabled -eq $false}
You can use the properties DisplayName and ComponentID to change their status. The next command activates IPv4 on the adapter with the name vEthernet.
Subscribe to 4sysops newsletter!
Set-NetAdapterBinding -Name vEthernet -ComponentID ms_tcpip -Enabled $true
Restarting an adapter
The cmdlet Restart-NetAdapter is useful if you have to modify settings. This corresponds to deactivating the interface and then activating it again through the GUI. It also ensures the renewal of the IP address through DHCP.
Unfortunately this ignores all teamed adapters so they’re not listed when you run the commandlet.
Is there a way to get the value of InterfaceIndex and move it to a variable?