diff --git a/MyScripts/Bootstrap-RemoteHostViaSSH.ps1 b/MyScripts/Bootstrap-RemoteHostViaSSH.ps1 index e5d52cb..b8168aa 100644 --- a/MyScripts/Bootstrap-RemoteHostViaSSH.ps1 +++ b/MyScripts/Bootstrap-RemoteHostViaSSH.ps1 @@ -253,18 +253,30 @@ New-NetFirewallRule -Name wsl_sshd -DisplayName 'OpenSSH Server (sshd) for WSL' # Now we want to create a scheduled task that will start WSL AND ssh within WSL on boot $ScriptOutputPath = "C:\Scripts\bin\wsl_sshd.ps1" $ScriptContentAsString = @' -# Set Log Info +# Set Log Info and WSL Instance Name $LogFileDir = "C:\Scripts\logs" $LogFilePath = $LogFileDir + '\' + 'start_wsl_sshd_' + $(Get-Date -Format MMddyy_hhmmss) + '.log' +$WslInstanceName = "Ubuntu" # Start SSH service in WSL bash.exe -c "sudo /usr/sbin/service ssh start" +#wsl --distribution "$WslInstanceName" --user root /bin/sh -c "/usr/sbin/service ssh start" # Remove port proxy rule netsh.exe interface portproxy delete v4tov4 listenport=2222 listenaddress=0.0.0.0 protocol=tcp # Get IP address from WSL -$IP = (wsl.exe hostname -I).Trim() +try { + $IP = (wsl.exe hostname -I).Trim() + #$IPPrep = wsl --distribution "$WslInstanceName" --user root /bin/sh -c "ip addr show eth0 | grep 'inet ' | awk '{print `$2}' | cut -d/ -f1" + #$IPPrep = bash.exe -c "ip addr show eth0 | grep 'inet ' | awk '{print `$2}' | cut -d/ -f1" + #$IP = ($IPPrep -split "[\s]")[-1].Trim() +} catch { + $ErrMsg = $_.Exception.Message + $null = Add-Content -Path $LogFilePath -Value $ErrMsg + Write-Error $ErrMsg + return +} if (!$IP) { $null = Add-Content -Path $LogFilePath -Value 'Unable to identify wsl IP Address via: (wsl.exe hostname -I).Trim()'