[英]How can I display, enable or disable all the Network adapters using PowerShell 5 in windows 7?
I am very new to PowerShell. 我对PowerShell非常陌生。 I am using Windows 7 and PowerShell 5. 我正在使用Windows 7和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. 但是问题是,我无法使用此命令一起禁用所有pf网络适配器。
$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! 提前致谢!
It's because you're calling .disable()
on the collection of network adapters and this method only exists for a single network adpater. 这是因为您要在网络适配器集合上调用.disable()
,而此方法仅适用于单个网络适配器。
Try this: 尝试这个:
$wmi = get-wmiobject win32_networkadapter
$wmi | Foreach-Object {
Write-Host "Disabling: $($_.name)"
$_.disable()
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.