简体   繁体   English

如何在Windows 7中使用PowerShell 5显示,启用或禁用所有网络适配器?

[英]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: 我正在尝试做的是:

  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. 但是问题是,我无法使用此命令一起禁用所有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.

相关问题 使用netsh / wmic禁用/启用所有网络适配器(NIC) - Disable/Enable All Network Adapters (NIC) using netsh/wmic 如何以编程方式启用/禁用网络连接选项 - How can I enable/disable network connection options programmatically 如何在.NET中启用或禁用Windows服务? - How can I enable or disable a windows service in .NET? 如何在 Windows 中通过 C# 代码启用/禁用网络协议 - How to enable / disable network protocols from C# code in Windows 使用java在Windows中获取网络适配器的“媒体状态”? - Obtain “Media State” of network adapters in windows using java? 在不使用WMI的情况下获取所有网络适配器的MAC地址 - Get MAC address for all network adapters without using WMI 启用和禁用TLS和SSL在IE中,在Z0F4137ED1502B5045D6045D6083AA258B58B5C42Z中使用本地机器(不是Z0F4137ED152B502B502602605DDEMEA) - Enable and Disable TLS and SSL in IE on windows 10 local machine(not windows server) using powershell 希望通过Powerscript启用/禁用两个网络适配器 - Looking to enable/disable two networking adapters with Powerscript 如何在 Windows Server 2008 上禁用 Java 中的所有网络连接 - How to disable all network connections in Java on Windows Server 2008 使用 Python,如何访问 windows 网络上的共享文件夹? - Using Python, how can I access a shared folder on windows network?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM