Skip to content

Instantly share code, notes, and snippets.

@crozone
Created June 30, 2023 03:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crozone/78d82c5db08f4a02db74a89634bc27ed to your computer and use it in GitHub Desktop.
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.
# 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