Skip to content

Commit

Permalink
Caller scripts no longer terminate unwantedly
Browse files Browse the repository at this point in the history
when Get-SshSession and Remove-SshSession -RemoveAll are used.
  • Loading branch information
EliteLoser authored Feb 18, 2018
1 parent 5eefc1d commit d867a64
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions SSHSessions.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,12 @@ function Remove-SshSession {
}
}
if ($Global:SshSessions.Keys.Count -eq 0) {
Write-Error -Message "Parameter -RemoveAll specified, but no hosts found." -ErrorAction Stop
break
Write-Warning -Message "Parameter -RemoveAll specified, but no hosts found."
# This terminates the calling script (I had noe clue it behaved like that, honestly, was surprised).
# My workaround is relying on that the above check for both -ComputerName and -RemoveAll
# makes the process block moot unless someone is piping in, in which case Get-SshSession will halt before
# this advanced function is called. Based on feedback.
#break
}
# Get all computer names from the global SshSessions hashtable.
$ComputerName = $Global:SshSessions.Keys | Sort-Object
Expand Down Expand Up @@ -511,8 +515,9 @@ function Get-SshSession {
begin {
# Just exit with a message if there aren't any connections.
if ($Global:SshSessions.Count -eq 0) {
Write-Error -Message "No connections found"
break
Write-Warning -Message "No connections found."
# This terminates the calling script too (so I learned today, at least in v5.1). Removing.
#break
}
}
process {
Expand Down

0 comments on commit d867a64

Please sign in to comment.