Updated enter-host.ps1

This commit is contained in:
Markus Fleschutz 2024-10-25 15:30:01 +02:00
parent 7bc7da1b3b
commit ce36877c69

View File

@ -7,7 +7,8 @@
Specifies the remote hostname or IP address Specifies the remote hostname or IP address
.EXAMPLE .EXAMPLE
PS> ./enter-host.ps1 tux PS> ./enter-host.ps1 tux
💻 Entering 'tux' as user 'markus' using OpenSSH_for_Windows_9.5p1, LibreSSL 3.8.2 Connecting to 'tux' as user 'markus' using OpenSSH_for_Windows_9.5p1, LibreSSL 3.8.2
markus@tux's password:
... ...
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
@ -18,14 +19,20 @@
param([string]$remoteHost = "") param([string]$remoteHost = "")
try { try {
if ($remoteHost -eq "") { $remoteHost = Read-Host "Enter the remote hostname" } if ($remoteHost -eq "") {
if ($IsLinux) { $username = $(whoami) } else { $username = $env:USERNAME } $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
}
$username = $username.toLower() $username = $username.toLower()
Write-Host "💻 Entering '$remoteHost' as user '$username' using " -noNewline Write-Host "⏳ Connecting to '$remoteHost' as user '$username' using " -noNewline
& ssh -V & ssh -V
if ($lastExitCode -ne "0") { throw "'ssh -V' failed with exit code $lastExitCode" } if ($lastExitCode -ne "0") { throw "'ssh -V' failed with exit code $lastExitCode" }
Write-Host " (type 'exit' to leave $remoteHost)"
& ssh "$($username)@$($remoteHost)" & ssh "$($username)@$($remoteHost)"
exit 0 # success exit 0 # success