How darkoperator/posh-ssh works
Project type and purpose
• This is an open-source PowerShell module (“Posh-SSH”) that wraps a custom build of the SSH.NET library to provide SSH, SCP and SFTP cmdlets in PowerShell.
• It targets PowerShell 5.1 and 7.x on Windows, and via .NET Standard also runs on Linux and Mac.
• It is organized as a reusable .NET Standard library (PoshSSH.Core) plus a PowerShell module (.psm1, help files, format definitions, documentation).
File-structure overview and architectural insights
• Top-level directories:
– Posh-SSH/ (PowerShell module contents: .psd1 manifest, .psm1 implementation, XML format files, help files, en-US help folder)
– Source/PoshSSH/PoshSSH.Core (C# .NET Standard library housing core SSH logic)
– Source/PoshSSH/PoshSSH (C# sources defining PowerShell cmdlet classes, session objects, stores)
– docs/ (markdown documentation for each cmdlet)
– tests/ (Pester or PowerShell test scripts for core cmdlets)
• Key configuration files:
– Posh-SSH.psd1 (module manifest)
– Posh-SSH.psm1 (module entry point, exports functions)
– packages.config (SSH.NET dependency)
– launchSettings.json (development debug settings for Core library)
• Architectural patterns:
– Separation of concerns: PowerShell-specific plumbing in the module, core SSH and file-transfer logic in the .NET Standard library.
– Strategy/Factory for different “Stores” (JsonStore, MemoryStore, OpenSSHStore) implementing IStore.
– Cmdlet classes map one-to-one with user-facing commands (Get-SSHSession, New-SFTPSession, etc.).
Main components and their relationships
• PowerShell Host (CLI or script)
→ invokes exported Cmdlets in Posh-SSH.psm1
• Posh-SSH PowerShell module
→ loads PoshSSH.Core assembly
→ cmdlet classes instantiate SessionObject, ConnectionInfoGenerator, OperationProgressHelper
→ use IStore implementations to read/write known-hosts or session credentials
• PoshSSH.Core (.NET Standard)
→ wraps SSH.NET library calls (Renci.SshNet) for SSH session establishment, file operations, port forwarding
→ exposes high-level methods (Connect, DownloadFile, UploadDirectory, InvokeCommand, ForwardPort)
• External dependency:
→ SSH.NET library (Renci.SshNet.dll) as the low-level SSH protocol engine
• Data flow:
PowerShell cmdlet call → Core API → SSH.NET → Remote SSH server
• Persistence flows:
Core uses IStore to load or save known-hosts in JSON, OpenSSH format or in-memory.
Architectural patterns and design principles
• Layered design: Separation between shell-specific layer and core networking logic.
• Dependency inversion: Cmdlets depend on interfaces (IStore) and abstract core services.
• Single responsibility: Each cmdlet focuses on one SSH/SFTP/SCP/port-forward operation.
• Extensibility: New stores or session types can be added by implementing IStore or by adding new cmdlet classes.
Detailed capture
• Module manifest loading step and format file usage for output formatting
• Call out test harness as a side‐component invoking PowerShell against module for CI