mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-02-16 17:51:28 +01:00
Updated enter.ps1
This commit is contained in:
parent
43b15cd1ef
commit
702506f9a1
@ -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])"
|
||||||
|
Loading…
Reference in New Issue
Block a user