0

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!

1
  • @Lachie Thanks for editing all my mistakes :) Commented Feb 22, 2017 at 10:43

1 Answer 1

2

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()
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.