mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-04-28 12:48:45 +02:00
Updated enter.ps1
This commit is contained in:
parent
21e8911239
commit
c13e3c3dbd
@ -1,8 +1,8 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
SSH login to another host
|
Login to another host via SSH
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This PowerShell script logs into another host by SSH.
|
This PowerShell script logs into a remote host via secure shell (SSH).
|
||||||
.PARAMETER remoteHost
|
.PARAMETER remoteHost
|
||||||
Specifies the remote hostname or IP address
|
Specifies the remote hostname or IP address
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
@ -20,9 +20,12 @@ try {
|
|||||||
if ($IsLinux) { $username = $(whoami) } else { $username = $env:USERNAME }
|
if ($IsLinux) { $username = $(whoami) } else { $username = $env:USERNAME }
|
||||||
$username = $username.toLower()
|
$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
|
& ssh -V
|
||||||
|
if ($lastExitCode -ne "0") { throw "'ssh -V' failed with exit code $lastExitCode" }
|
||||||
|
|
||||||
& ssh "$($username)@$($remoteHost)"
|
& ssh "$($username)@$($remoteHost)"
|
||||||
|
if ($lastExitCode -ne "0") { throw "'ssh -V' failed with exit code $lastExitCode" }
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
|
Loading…
Reference in New Issue
Block a user