Reputation: 4216
I am very new to PowerShell. I am using Windows 7 and PowerShell 5.
What I am trying to do is:
display all the network adapters for a system.
Disable all of them
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
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