- December 5, 2023
- Posted by: Surender Kumar
- Category: Windows 11
Programmatically create a network bridge in Windows
Did you ever get stuck when creating a network bridge programmatically? You can do that quickly with the graphical user interface (GUI), as shown in the screenshot below.
But what if you want to create a bridge without using the GUI option? Well, it is not possible until you upgrade the operating system to Windows 11 (build 22621.2361). With this build version, Microsoft added the
netsh bridge create command that helps you create a bridge. Without this command, your choice was only limited to the GUI.
Using the Netsh command
First, ensure you are running 22621.2361 build version of Windows 11. You can check that by running the
winver command. To create a network bridge, launch an elevated PowerShell console and run these commands:
$adapter1 = Get-NetAdapter -Name 'eth0' $adapter2 = Get-NetAdapter -Name 'eth1' netsh bridge create $adapter1.name $adapter2.name
These commands will create a new network bridge with two network interfaces (eth0 and eth1), as shown in the screenshot below:
Once the bridge is created, run the
netsh bridge list command to view it.
This command shows you the bridge GUID. To add/remove the adapter to/from the bridge, you can use the commands shown below:
netsh bridge add <adapter_id> to <bridge_guid> netsh bridge remove <adapter_id> from <bridge_guid>
The adapter ID can be a GUID, name, or interface index (IfIndex) and the bridge GUID can be obtained with the “netsh bridge list” command, as shown previously. To remove all network adapters from a bridge and destroys the bridge itself, run the following command:
netsh bridge remove all from <bridge_guid>
You can also delete the bridge by running this command:
netsh bridge destroy <bridge_guid>
That was all for this post. You just learned how to create and manage a network bridge with PowerShell.