Enable and Disable an Network Adapter using PowerShell

u can type and run ” ncpa.cpl” in powershell
it will open windows network adapter listing and setting

1. WMIC
in powershell (Run as Admin):

wmic nic get name","index


PS C:\Users\chako> wmic nic get name","index
Index  Name
0      Intel(R) Ethernet Connection I217-V
1      Realtek PCIe GBE Family Controller
2      Broadcom 802.11ac Network Adapter
3      Microsoft Kernel Debug Network Adapter
4      Microsoft Wi-Fi Direct Virtual Adapter
5      WAN Miniport (SSTP)
6      WAN Miniport (IKEv2)
7      WAN Miniport (L2TP)
8      WAN Miniport (PPTP)
9      WAN Miniport (PPPOE)
10     WAN Miniport (IP)
11     WAN Miniport (IPv6)
12     WAN Miniport (Network Monitor)
13     Microsoft ISATAP Adapter
14     Microsoft Teredo Tunneling Adapter
15     Bluetooth Device (Personal Area Network)
16     Bluetooth Device (RFCOMM Protocol TDI)
17     Microsoft KM-TEST Loopback Adapter
18     VMware Virtual Ethernet Adapter for VMnet1
19     VMware Virtual Ethernet Adapter for VMnet8
25     VirtualBox Host-Only Ethernet Adapter
26     Microsoft ISATAP Adapter #6


PS C:\Windows\system32> wmic path win32_networkadapter where index=18 call enable
Executing (\\DESKTOP-G0J7PAP\root\cimv2:Win32_NetworkAdapter.DeviceID="18")->enable()
Method execution successful.
Out Parameters:
instance of __PARAMETERS
{
        ReturnValue = 0;
};



2. netsh
in powershell (Run as Admin):



PS C:\Windows\system32> netsh interface show interface

Admin State    State          Type             Interface Name
-------------------------------------------------------------------------
Enabled        Disconnected   Dedicated        Ethernet
Disabled       Disconnected   Dedicated        Npcap Loopback Adapter
Disabled       Disconnected   Dedicated        VirtualBox Host-Only Network
Disabled       Disconnected   Dedicated        VMware Network Adapter VMnet1
Disabled       Disconnected   Dedicated        VMware Network Adapter VMnet8
Enabled        Connected      Dedicated        Wi-Fi
Enabled        Disconnected   Dedicated        Ethernet 2



Disable Ethernet :

netsh interface set interface "Ethernet" disabled



3. Get-NetAdapter
in powershell (Run as Admin):


PS C:\Windows\system32> Get-NetAdapter

Name                      InterfaceDescription                    ifIndex Status       MacAddress             LinkSpeed
----                      --------------------                    ------- ------       ----------             ---------
Ethernet 2                Realtek PCIe GBE Family Controller           20 Disconnected 70-A0-20-0B-0A-99          0 bps
Wi-Fi                     Broadcom 802.11ac Network Adapter             9 Up           54-CA-6B-A1-A3-23        78 Mbps
VMware Network Adapte...8 VMware Virtual Ethernet Adapter for ...       3 Not Present  00-50-56-C0-00-08          0 bps
VMware Network Adapte...1 VMware Virtual Ethernet Adapter for ...      10 Disabled     00-50-56-C0-00-01       100 Mbps
VirtualBox Host-Only N... VirtualBox Host-Only Ethernet Adapter        23 Not Present  0A-00-27-00-00-1B          0 bps
Npcap Loopback Adapter    Npcap Loopback Adapter                       19 Not Present  A2-00-CC-CC-FF-5A          0 bps
Ethernet                  Intel(R) Ethernet Connection I217-V          16 Disabled     50-D0-AB-CB-FB-99          0 bps



PS C:\Windows\system32> Get-NetAdapter -Name Ethernet | Enable-NetAdapter
PS C:\Windows\system32> Get-NetAdapter -Name Ethernet | Disable-NetAdapter

Confirm
Are you sure you want to perform this action?
Disable-NetAdapter 'Ethernet'
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): y
PS C:\Windows\system32>


[reference]
https://support.microsoft.com/en-za/help/192806/how-to-run-control-panel-tools-by-typing-a-command