Introduction

Windows allows you to manage the priority of network adapters to ensure the preferred network interface is used for traffic. Using PowerShell, you can easily list the current network interfaces and adjust their priority to optimize network performance.

Listing Network Adapters

To list all network adapters and their current priority, use the Get-NetIPInterface cmdlet:

Get-NetIPInterface

This command provides a detailed list of all network interfaces, including their interface alias, address family, and interface metric (priority).

Setting Network Adapter Priority

To change the priority of a specific network adapter, use the Set-NetIPInterface cmdlet. For example, to set the priority of the adapter named “vEthernet (Vlan)” to 1, use the following command:

Set-NetIPInterface -InterfaceAlias "vEthernet (Vlan)" -InterfaceMetric 1

The -InterfaceMetric parameter specifies the priority, with a lower number indicating higher priority.

Example Script

Here is a complete PowerShell script to list the network adapters and set the priority for a specific adapter:

# List all network adapters
Get-NetIPInterface

# Set the priority of a specific network adapter
$adapterName = "vEthernet (Vlan)"
$priority = 1
Set-NetIPInterface -InterfaceAlias $adapterName -InterfaceMetric $priority

# Confirm the change
Get-NetIPInterface | Where-Object { $_.InterfaceAlias -eq $adapterName }

This script lists all network adapters, sets the priority of the specified adapter, and confirms the change by listing the details of the updated adapter.

Steps to Run the Script

  1. Open PowerShell with administrative privileges.
  2. Copy and paste the script into the PowerShell console or save it as a .ps1 file.
  3. Modify the $adapterName and $priority variables as needed.
  4. Execute the script to list the network adapters and update the priority.

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.