【发布时间】:2015-09-16 22:58:34
【问题描述】:
我正在寻找一种使用 PowerShell 在 Windows 8.1 中打开和关闭移动宽带连接的方法。如果没有纯 PowerShell cmdlet,本机 cmd.exe 方式也可能就足够了。目前,我知道如何禁用和启用适配器本身,但不知道连接。万一很重要:PC内置3G模块。
我尝试比较了适配器在连接和断开状态下的属性:
Get-NetAdapter -Name "Mobile broadband" | select -Property * | Out-File connected.txt
# manually disconnected
Get-NetAdapter -Name "Mobile broadband" | select -Property * | Out-File disconnected.txt
Compare-Object $(Get-Content connected.txt) $(Get-Content disconnected.txt)
并得到以下结果:
InputObject SideIndicator
----------- -------------
Status : Disco... =>
LinkSpeed : 0 bps =>
MediaConnectionState : Disco... =>
ifOperStatus : Down =>
Speed : 0 =>
InterfaceOperationalStatus : 2 =>
MediaConnectState : 2 =>
OperationalStatusDownMediaDisconnected : True =>
ReceiveLinkSpeed : 0 =>
TransmitLinkSpeed : 0 =>
Status : Up <=
LinkSpeed : 21.6 ... <=
MediaConnectionState : Conne... <=
ifOperStatus : Up <=
Speed : 21600000 <=
InterfaceOperationalStatus : 1 <=
MediaConnectState : 1 <=
OperationalStatusDownMediaDisconnected : False <=
ReceiveLinkSpeed : 5760000 <=
TransmitLinkSpeed : 21600000 <=
但是,我似乎无法更改任何这些选项,因为它们对我来说是只读的:
Get-NetAdapter -Name "Mobile broadband" | Get-Member -Name Status,MediaConnectionState,ifOperStatus,InterfaceOperationalStatus,MediaConnectState,OperationalStatusDownMediaDisconnected
TypeName: Microsoft.Management.Infrastructure.CimInstance#ROOT/StandardCimv2/MSFT_NetAdapter
Name MemberType Definition
---- ---------- ----------
Status ScriptProperty System.Object Status {get=$NetAdapter = $this;...
MediaConnectionState ScriptProperty System.Object MediaConnectionState {get=[Microsoft.PowerShell....
ifOperStatus ScriptProperty System.Object ifOperStatus {get=[Microsoft.PowerShell.Cmdletiz...
InterfaceOperationalStatus Property uint32 InterfaceOperationalStatus {get;}
MediaConnectState Property uint32 MediaConnectState {get;}
OperationalStatusDownMediaDisconnected Property bool OperationalStatusDownMediaDisconnected {get;}
我也无法使用 Enable-NetAdapter cmdlet 更改连接状态。
【问题讨论】:
-
我认为您应该在适配器级别工作,至少尝试在 GUI 中禁用连接并检查适配器的 WMI 对象是否将
NetEnabled设置为 false。如果是,这些操作是完全相等的。 -
@Vesper 对不起,我不明白你的意思。我在描述中添加了额外的信息,也许会有用。
-
嗯,您的 3G 与系统的连接类型是什么?它是一种调制解调器/VPN吗?我的意思是,3G 上的“网络连接”窗口中显示的是什么类型的连接?如果是拨号或VPN,请查看
Get-VPNConnection了解控制连接的方法。 -
@Vesper 这似乎不是 VPN 连接,因为 Get-VPNConnection 无法通过名称或 * 通配符找到它。我也从未输入任何凭据。在“网络连接”中,仅显示“华为移动宽带模块”,并没有额外说明连接类型。此外,在 Windows 8 GUI 的“网络”部分中,有一个“移动宽带”子部分和一个简单的滑块来切换它 - 与飞行模式和 Wi-Fi 的滑块相同。额外注意的是,新安装的 Windows 8.1(通用,不是特定于设备)检测到连接,而我无需安装任何额外的驱动程序。
-
您找到解决方案了吗?
标签: windows powershell wireless