Skip to content

enter-host

Enter another host via SSH

#Requires -Version 5.1

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
} catch {
throw
}

Specifies the remote hostname or IP address

An interactive directory of PowerShell scripts.