Srijani Ghosh
Srijani Ghosh

Reputation: 4216

How can I display, enable or disable all the Network adapters using PowerShell 5 in windows 7?

I am very new to PowerShell. I am using Windows 7 and PowerShell 5.

What I am trying to do is:

  1. display all the network adapters for a system.

  2. Disable all of them

  3. Enable all of them

I am using this code to display all the network adapters:

$wmi = get-wmiobject win32_networkadapter

This displays all the network adapters and their status. But the problem is that, I am not able to disable all pf the network adapters together using this command.

$wmi.disable()

This statement gives me the error:

Method invocation failed because [Selected.System.Management.ManagementObject] does not contain a method named 'disable'.
At line:1 char:1
+ $wmi.disable()
+ ~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (disable:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

Is there any alternative way to display all the network adapters and disable or enable all of them together ?

Thanks in advance!

Upvotes: 0

Views: 1245

Answers (1)

TechSpud
TechSpud

Reputation: 3518

It's because you're calling .disable() on the collection of network adapters and this method only exists for a single network adpater.

Try this:

$wmi = get-wmiobject win32_networkadapter
$wmi | Foreach-Object {
  Write-Host "Disabling: $($_.name)"
  $_.disable()
}

Upvotes: 2

Related Questions