CodeSteps

Python, C, C++, C#, PowerShell, Android, Visual C++, Java ...

PowerShell – How to enable or disable network adapters?

PowerShell provides a set of cmdlets to enable or disable network adapters. These cmdlets we are going to discuss through this article, are in NetAdapter module.

Enable a network adapter

Enable-NetAdapter cmdlet enables a network adapter. To connect to the network, network adapters must be enabled.

Through its’ -Name the parameter we can pass the name of the network adapter we would like to enable.

PS C:\> Enable-NetAdapter -Name "Wi-Fi"

When we call this cmdlet without passing the parameters, by default it will prompt us to give the values for the-Name parameter, as shown below.

PS C:\> Enable-NetAdapter

cmdlet Enable-NetAdapter at command pipeline position 1
Supply values for the following parameters:
Name[0]: Wi-Fi
Name[1]:
PS C:\>

Ensure to pass the right network adapter name through its’ parameter -Name. Otherwise, you will see ObjectNotFound error. Also note that, do not mention the name of the network adapter in quotes when the cmdlet prompts for the name as it treats quotes are also part of the name and you will see the ObjectNotFound error. Here is an example;

PS C:\> Enable-NetAdapter

cmdlet Enable-NetAdapter at command pipeline position 1
Supply values for the following parameters:
Name[0]: "Wi-Fi"
Name[1]:
Enable-NetAdapter : No MSFT_NetAdapter objects found with property 'Name' equal to '"Wi-Fi"'.  Verify the
value of the property and retry.
At line:1 char:1
+ Enable-NetAdapter
+ ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: ("Wi-Fi":String) [Enable-NetAdapter], CimJobException
    + FullyQualifiedErrorId : CmdletizationQuery_NotFound_Name,Enable-NetAdapter

Disable a network adapter

Disable-NetAdapter cmdlet is used to disable the network adapters. By default, it will ask for confirmation before disabling the network adapter. Be cautious when you use this command, as this disables the network.

To disable the specific network adapter, we can pass its’ name through the -Name parameter.

PS C:\> Disable-NetAdapter -Name "Wi-Fi"

We can also use wildcards through the -Name parameter to disable multiple or all network adapters.

PS C:\> Disable-NetAdapter -Name "*"

Please note that you must have the required permissions to disable network adapters. Otherwise, you will see the Access Denied error message.

PS C:\> Disable-NetAdapter -Name "Wi-Fi"

Confirm
Are you sure you want to perform this action?
Disable-NetAdapter 'Wi-Fi'
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): Y
Disable-NetAdapter : Access is denied.
At line:1 char:1
+ Disable-NetAdapter -Name "Wi-Fi"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (MSFT_NetAdapter...XXXXXXXXXXXXX"):ROOT/StandardCimv2/MSFT_NetAdapter) [Disable-NetAdapter], CimException
    + FullyQualifiedErrorId : Windows System Error 5,Disable-NetAdapter

 

See also, “PowerShell – How to get network adapter details?“.

[..] David

PowerShell – How to enable or disable network adapters?

One thought on “PowerShell – How to enable or disable network adapters?

Leave a Reply

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

Scroll to top
Exit mobile version