< Back

Invoke-SSHStreamExpectAction

Sat Jan 18, 2020 7:57 pm

NAME Invoke-SSHStreamExpectAction



SYNOPSIS

Executes an action on a SSH ShellStream when output matches a desired string.





SYNTAX

Invoke-SSHStreamExpectAction [-ShellStream] <ShellStream> [-Command] <String> [-ExpectString] <String> [-Action]

<String> [[-TimeOut] <Int32>] [<CommonParameters>]



Invoke-SSHStreamExpectAction [-ShellStream] <ShellStream> [-Command] <String> [-ExpectRegex] <Regex> [-Action]

<String> [[-TimeOut] <Int32>] [<CommonParameters>]





DESCRIPTION

Executes an action on a SSH ShellStream when output matches a desired string. Function returns true if an action

was executed.





PARAMETERS

-ShellStream <ShellStream>

SSH Shell Stream.



Required? true

Position? 0

Default value None

Accept pipeline input? True (ByPropertyName, ByValue)

Accept wildcard characters? false



-Command <String>

Initial command that will generate the output to be evaluated by the expect pattern.



Required? true

Position? 1

Default value None

Accept pipeline input? True (ByPropertyName)

Accept wildcard characters? false



-ExpectString <String>

String on what to trigger the action on.



Required? true

Position? 2

Default value None

Accept pipeline input? True (ByPropertyName)

Accept wildcard characters? false



-Action <String>

Command to execute once an expression is matched.



Required? true

Position? 3

Default value None

Accept pipeline input? True (ByPropertyName)

Accept wildcard characters? false



-TimeOut <Int32>

Number of seconds to wait for a match.



Required? false

Position? 4

Default value None

Accept pipeline input? True (ByPropertyName)

Accept wildcard characters? false



-ExpectRegex <Regex>

Regular expression on what to trigger the action on.



Required? true

Position? 2

Default value None

Accept pipeline input? True (ByPropertyName)

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS

Renci.SshNet.ShellStream





System.String





System.Int32





System.Text.RegularExpressions.Regex







OUTPUTS

System.Boolean







NOTES









Example 1



PS C:\\> Invoke-SSHStreamExpectAction -ShellStream $ShellStream -Command "config" -ExpectRegex '[\\$%#>] $' -Action

'set interface eth0 address 10.10.10.240\\24' -Verbose



Run second command if the regex for a prompt matches.



RELATED LINKS

Online Version: https://github.com/darkoperator/Posh-SS ... aster/docs