我正在寻找一种使用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更改连接状态。
答案 0 :(得分:0)
使用.Net框架连接到任何类型的网络cannot。但是要连接到移动连接,您可以在命令提示符下键入NETSH MBN CONNECT INTERFACE=<ADAPTER_NAME> CONNMODE=NAME NAME=<CONNECTION_PROFILE_NAME>
来完成此操作。在您的情况下,ADAPTER_NAME将为“移动宽带”,并且您可以使用以下PowerShell命令找到CONNECTION_PROFILE_NAME的值:Get-NetConnectionProfile -InterfaceAlias "Mobile broadband" | Select-Object Name
要断开与网络的连接,请使用NETSH MBN DISCONNECT <ADAPTER_NAME>
。