Skip to content

Instantly share code, notes, and snippets.

@lucasraziel
Created April 11, 2020 03:24
Show Gist options
  • Save lucasraziel/48bc1115604a2baca373e8db2e34d82d to your computer and use it in GitHub Desktop.
Save lucasraziel/48bc1115604a2baca373e8db2e34d82d to your computer and use it in GitHub Desktop.
wsl2 adb
$currentSript = $PSScriptRoot + "\adb-start.ps1"
$adbPath = "C:\Program Files (x86)\Android\android-sdk\platform-tools"
$adbPort = 5037
$adbListenAddress = '0.0.0.0'
$adbConnectAddress = '127.0.0.1'
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
if ($currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) -eq $FALSE)
{
Start-Process "powershell.exe" -ArgumentList $currentSript -WindowStyle hidden -Verb runAs
}
# Set ADB path
Set-Location $adbPath
# Remove port mapping
netsh interface portproxy delete v4tov4 listenport=$adbPort listenaddr=$adbListenAddress
# Kill server
./adb.exe kill-server
# Start server
./adb.exe start-server
# Add port mapping
netsh interface portproxy add v4tov4 listenport=$adbPort listenaddr=$adbListenAddress connectport=$adbPort connectaddr=$adbConnectAddress
# Display portproxy
netsh interface portproxy show v4tov4
# Start WSL
wsl --exec exit
# Remove firewall rule for WSL
Set-NetFirewallProfile -DisabledInterfaceAliases "vEthernet (WSL)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment