Reputation: 748
I have a tiny .ps1
script which switches a network connection between Ethernet and WiFi. My script works well. I now want to know how to switch off WiFi without disabling the underlying network adapter.
Here is my existing script:
$lanState = Get-NetAdapter -Name MyEthernetPort | where status -EQ 'up'
if ( $lanState )
{
write-host 'Enabled... Disable now'
Get-NetAdapter -Name MyEthernetPort | ? status -NE disabled | Disable-NetAdapter -Confirm:$false
# TODO switch on wifi
netsh wlan connect name=SM-GUEST
}
else
{
Write-Host 'Disabled... Enable now'
Get-NetAdapter -Name MyEthernetPort | ? status -EQ disabled | Enable-NetAdapter -Confirm:$false
# TODO switch off wifi
netsh wlan disconnect
}
I haven't been able to find any guidance on how to switch off WiFi via PowerShell (in the same way as it would occur if you clicked the button in the Windows 10 info center). All scripts that I've found just disable the underlying adapter, which is not what I want.
Can anybody suggest how to access this functionality from PowerShell?
Upvotes: 7
Views: 24579
Reputation: 27423
Disabling and Enabling works for me. The status becomes disconnected instead of up.
Get-NetAdapter | ? PhysicalMediaType -eq 'Native 802.11'| disable-netadapter}
Get-NetAdapter | ? PhysicalMediaType -eq 'Native 802.11'| enable-netadapter }
Get-NetAdapter | ? PhysicalMediaType -eq 'Native 802.11'
Name InterfaceDescription ifIndex Status MacAddress LinkSpeed
---- -------------------- ------- ------ ---------- ---------
Wi-Fi Intel(R) Wi-Fi 6 AX201 160MHz 5 Disconnected F8-94-B5-84-BF-53 0 bps
Upvotes: 0
Reputation: 51
I try to solve same problem, and thx for nandubhadu hints.
Comapre wifi off/on,then I found RegistryKeyword SoftwareRadioOff is different between two status.
turn on(as administrator)
powershell Set-NetAdapterAdvancedProperty -Name "Wi-Fi" -AllProperties -RegistryKeyword "SoftwareRadioOff" -RegistryValue "0"
turn off(as administrator)
powershell Set-NetAdapterAdvancedProperty -Name "Wi-Fi" -AllProperties -RegistryKeyword "SoftwareRadioOff" -RegistryValue "1"
I use it in my connect wifi script, it works on my Win10 notebook now.
Upvotes: 5
Reputation: 31
These are the commands which worked in command prompt
Check radio status
powershell Get-NetAdapterAdvancedProperty -Name "Wi-Fi" -AllProperties -RegistryKeyword "radioEnable"
To turn radio on (run as administrator)
powershell Set-NetAdapterAdvancedProperty -Name "Wi-Fi" -AllProperties -RegistryKeyword "radioEnable" -RegistryValue "1"
To turn radio off (run as administrator)
powershell Set-NetAdapterAdvancedProperty -Name "Wi-Fi" -AllProperties -RegistryKeyword "radioEnable" -RegistryValue "0"
to use these commands in powershell just remove powershell from beginning
Upvotes: 0
Reputation: 1
I only open the "computer managenent" then open "device manager" then "network adapters" after that I disable the "wireless" and then I enable it again. My wireless is activa again
Upvotes: -5
Reputation: 23355
I can't find any way to do this programmatically, and as a result I think the answer might be that it's (currently) not entirely possible.
What I have found is that when you use the button in the Windows action center to turn off Wifi, netsh
shows the interface as "Hardware On" "Software Off":
Netsh WLAN show interfaces
There is 1 interface on the system:
Name : WiFi
State : disconnected
Radio status : Hardware On
Software Off
However I can't see any ability to trigger "Software Off" via netsh
or any of the *-netadapter
cmdlets. It might be that this is controlled via a switch in the registry but if so I can't see which.
My recommendation would be to just continue controlling wifi by enabling/disabling the underlying adapter with Disable-NetAdapter
and Enable-NetAdapter
or if it's the case that you need to keep the hardware enabled (perhaps in order to reconfigure it?) but want the wireless to be disconnected while you do so, you could connect/disconnect the network via:
netsh wlan disconnect
netsh wlan connect
Upvotes: 4