首页 > 解决方案 > 如何使用 PowerShell 查找不同语言的 wifi 适配器

问题描述

powershell 脚本应该启用/禁用无线网络适配器。所以我使用了 NetAdaper cmdlet。

Get-NetAdapter
Enable-NetAdapter -Name 'Wi-Fi'-Confirm:$false
Disable-NetAdapter -Name 'Wi-Fi'-Confirm:$false

它在英语语言系统上运行良好。在配置了其他语言的系统上,由于无线适配器没有“Wi-Fi”作为名称,它会失败。

例如德语。

Enable-NetAdapter -Name 'WLAN'-Confirm:$false
Disable-NetAdapter -Name 'WLAN'-Confirm:$false

如何归档在所有语言上运行的这个脚本?

标签: windowspowershellwireless

解决方案


Get-NetAdapter有一个名为的字段InterfaceType,其中包含基于此枚举的值:

https://docs.microsoft.com/en-us/dotnet/api/system.net.networkinformation.networkinterfacetype?view=net-5.0

根据该文档, type71是一个Wireless80211设备。

只是为了表明它在那里:

[int][System.Net.NetworkInformation.NetworkInterfaceType]::Wireless80211

所以你可以做这样的事情:

Get-NetAdapter | Where-Object InterfaceType -eq 71

这将返回所有无线适配器的列表。


推荐阅读