Updated enter.ps1

This commit is contained in:
Markus Fleschutz 2024-10-01 22:10:48 +02:00
parent 43b15cd1ef
commit 702506f9a1

View File

@ -3,8 +3,8 @@
SSH login to another host SSH login to another host
.DESCRIPTION .DESCRIPTION
This PowerShell script logs into another host by SSH. This PowerShell script logs into another host by SSH.
.PARAMETER hostName .PARAMETER remoteHost
Specifies the hostname or IP address Specifies the remote hostname or IP address
.EXAMPLE .EXAMPLE
PS> ./enter.ps1 linuxhost PS> ./enter.ps1 linuxhost
.LINK .LINK
@ -13,15 +13,16 @@
Author: Markus Fleschutz | License: CC0 Author: Markus Fleschutz | License: CC0
#> #>
param([string]$hostName = "") param([string]$remoteHost = "")
try { try {
if ($hostName -eq "") { $hostName = Read-Host "Enter the target hostname" } if ($remoteHost -eq "") { $remoteHost = Read-Host "Enter the remote hostname" }
if ($IsLinux) { $username = $(whoami) } else { $username = $env:USERNAME } if ($IsLinux) { $username = $(whoami) } else { $username = $env:USERNAME }
$username = $username.toLower()
Write-Host "Entering host '$hostName' as user '$username' using " -noNewline Write-Host "Entering remote host '$remoteHost' as user '$username' using " -noNewline
& ssh -V & ssh -V
& ssh "$($username)@$($hostName)" & ssh "$($username)@$($remoteHost)"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"