Created
June 30, 2023 03:34
-
-
Save crozone/78d82c5db08f4a02db74a89634bc27ed to your computer and use it in GitHub Desktop.
Powershell script to rapidly switch between WiFi and Ethernet on Surface Book and MS Dock.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Script to switch between wired LAN and WiFi on Surface Book and MS Dock. | |
# Initially, one should be disabled and the other enabled. The script will then flip their states. | |
[string]$wifi_ifdesc = 'Marvell AVASTAR Wireless-AC Network Controller' | |
[string]$eth_ifdesc = 'Surface Ethernet Adapter #2' | |
if((Get-NetAdapter -InterfaceDescription $wifi_ifdesc).Status -eq 'Disabled') { | |
# Switch to Wifi | |
Write-Output 'Switching to WiFi' | |
Write-Output "Disabling $eth_ifdesc" | |
Disable-NetAdapter -InterfaceDescription $eth_ifdesc -Confirm:$False | |
Write-Output "Enabling $wifi_ifdesc" | |
Enable-NetAdapter -InterfaceDescription $wifi_ifdesc -Confirm:$False | |
} | |
elseif((Get-NetAdapter -InterfaceDescription $eth_ifdesc).Status -eq 'Disabled') { | |
# Switch to Surface Dock Ethernet | |
Write-Output 'Switching to Ethernet' | |
Write-Output "Disabling $wifi_ifdesc" | |
Disable-NetAdapter -InterfaceDescription $wifi_ifdesc -Confirm:$False | |
Write-Output "Enabling $eth_ifdesc" | |
Enable-NetAdapter -InterfaceDescription $eth_ifdesc -Confirm:$False | |
} | |
else { | |
Write-Output 'Nothing to do.' | |
} | |
Write-Output 'Done.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment