Skip to content

Instantly share code, notes, and snippets.

@pushrbx
Last active May 23, 2022 12:56
Show Gist options
  • Save pushrbx/554acb5bcfaaff40ca47b16970732015 to your computer and use it in GitHub Desktop.
Save pushrbx/554acb5bcfaaff40ca47b16970732015 to your computer and use it in GitHub Desktop.
# https://github.com/shayne/go-wsl2-host is needed for this
# a powershell command to setup the wslhost after you started the first wsl shell after a pc startup
# this will help you update the hosts file with the wsl's ip address
# it's kind of a workaround for a situation where you don't want to run wsl2-host app as a service
function setup-wslhost {
$myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent()
$myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID)
$adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator
if ($myWindowsPrincipal.IsInRole($adminRole))
{
$job = start-job -scriptblock { & wsl2host debug }
start-sleep -seconds 15
stop-job $job
write-host "wsl host set."
}
else {
Write-Host "Elevated prompt is required."
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment