Curated Examples
Capture an SSH shell transcript
Use Transferetto to retain and export a transcript from an interactive SSH shell.
This pattern is useful when you want to keep a readable record of what happened during an interactive shell workflow, especially for deployment or server troubleshooting.
It is adapted from the source example at Examples/Example26-SSHShellTranscript.ps1.
When to use this pattern
- An automation runs several shell commands in sequence.
- You want to review the shell dialogue after the fact.
- The workflow should persist a transcript to disk for logs or investigation.
Example
Import-Module Transferetto
$sshClient = Connect-SSH -Server 'server.example.com' -Credential (Get-Credential)
$shell = New-SSHShell -SshClient $sshClient -PromptPattern '(?m)^[^@\r\n]+@[^:\r\n]+:.*[$#]\s?$'
Invoke-SSHShellCommand -ShellSession $shell -Command 'cd /var/www/html && ls -la'
Invoke-SSHShellCommand -ShellSession $shell -Command 'sudo systemctl status nginx --no-pager'
Get-SSHShellTranscript -ShellSession $shell -AsText
Export-SSHShellTranscript -ShellSession $shell -Path "$PSScriptRoot\Logs\ssh-session.log"
Close-SSHShell -ShellSession $shell
Disconnect-SSH -SshClient $sshClient
What this demonstrates
- running multiple commands through one shell session
- reading the accumulated transcript in text form
- exporting the transcript for later review