Go-Host
Enter another host via SSH
param([string]$remoteHost = "")
try {
if ($remoteHost -eq "") {
$remoteHost = Read-Host "Enter the remote hostname or IP address"
$remoteUser = Read-Host "Enter the username at $remoteHost"
} elseif ($IsLinux) {
$remoteUser = $(whoami)
} else {
$remoteUser = $env:USERNAME
$remoteUser = $remoteUser.toLower()
}
& "$PSScriptRoot/ping-host.ps1" $remoteHost
if ($lastExitCode -ne 0) {
Write-Host "Let's try to wake '$remoteHost' up..."
& "$PSScriptRoot/wake-up-host.ps1"
}
Write-Host "? Connecting as user '$remoteUser' with " -noNewline
& ssh -V
if ($lastExitCode -ne 0) { throw "'ssh -V' failed with exit code $lastExitCode" }
& ssh "$($remoteUser)@$($remoteHost)"
exit 0 # success
} catch {
"?? ERROR: $($Error[0]) (script line $($_.InvocationInfo.ScriptLineNumber))"
exit 1
}Specifies the remote hostname or IP address