PowerShell script

# Run this as Administrator 
Write-Host "Retrieving WSL IP..." -ForegroundColor Cyan # Get WSL IP
$wslIp = wsl hostname -I | ForEach-Object { $_.Trim().Split(" ")[0] } if (-not $wslIp) {
   Write-Error "Could not retrieve WSL IP. Is WSL running?"
   exit 1
} 
Write-Host "WSL IP is $wslIp" -ForegroundColor Green # Ports to forward
$ports = @(80, 443) foreach ($port in $ports) {
   Write-Host "`nUpdating port $port..." -ForegroundColor Yellow    # Delete existing rule (if any)
   netsh interface portproxy delete v4tov4 listenport=$port listenaddress=0.0.0.0 > $null 2>&1    # Add new rule
   netsh interface portproxy add v4tov4 listenport=$port listenaddress=0.0.0.0 connectport=$port connectaddress=$wslIp
   netsh advfirewall firewall add rule name="WSL Apache Port $port" dir=in action=allow protocol=TCP localport=$port > $null 2>&1
   Write-Host "Port $port forwarded to ${wslIp}:$port" -ForegroundColor Green
}
Write-Host "`nMounting PHYSICALDRIVE0 to partion 1" -ForegroundColor Yellow
wsl --mount \\.\PHYSICALDRIVE0 --partition 1 --type ext4 
Write-Host "`nDone.`n" -ForegroundColor Cyan