Updated enter.ps1

This commit is contained in:
Markus Fleschutz 2024-10-04 21:13:53 +02:00
parent 21e8911239
commit c13e3c3dbd

View File

@ -1,8 +1,8 @@
<#
.SYNOPSIS
SSH login to another host
Login to another host via SSH
.DESCRIPTION
This PowerShell script logs into another host by SSH.
This PowerShell script logs into a remote host via secure shell (SSH).
.PARAMETER remoteHost
Specifies the remote hostname or IP address
.EXAMPLE
@ -20,9 +20,12 @@ try {
if ($IsLinux) { $username = $(whoami) } else { $username = $env:USERNAME }
$username = $username.toLower()
Write-Host "Entering remote host '$remoteHost' as user '$username' using " -noNewline
Write-Host "Trying to enter 💻$remoteHost as user '$username' using " -noNewline
& ssh -V
if ($lastExitCode -ne "0") { throw "'ssh -V' failed with exit code $lastExitCode" }
& ssh "$($username)@$($remoteHost)"
if ($lastExitCode -ne "0") { throw "'ssh -V' failed with exit code $lastExitCode" }
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"