This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Posh-SSH is a PowerShell module providing SSH, SFTP, and SCP functionality for Windows PowerShell 5.1 and PowerShell 7.x. It wraps the SSH.NET library to enable SSH automation against Linux/Unix servers from Windows, Linux, and macOS hosts.
Current version: 4.0.0 (see Posh-SSH/Posh-SSH.psd1). The v4.0 line is built against vanilla SSH.NET 2025.1.0 from NuGet — the legacy Cisco-patched Renci.SshNetDev.dll HintPath and the .NET Framework 4.7.2 project have both been removed.
-
C# Binary Module (
Source/PoshSSH/PoshSSH.Core/)- Single SDK-style csproj, target framework
netstandard2.0(cross-platform) - Compiles to
PoshSSH.dll - Auto-includes all
.csfiles under the project directory — no<Compile Link>indirection - Dependencies are pulled via
PackageReferenceonly:SSH.NET 2025.1.0,PowerShellStandard.Library 5.1.1 - Subdirectories:
Stores/— Trusted host store implementations:ITrustedHostStore,JsonTrustedHostStore,MemoryTrustedHostStore,OpenSSHTrustedHostStoreTrustedHost/— Trusted host cmdlets rewritten in C# (AddSshTrustedHost,GetSshTrustedHost,NewSshTrustedHost,RemoveSshTrustedHost,SetSshTrustedHost)
- Base class
NewSessionBase.csprovides shared connection scaffolding (ComputerName,Credential,Passphrase,.BeginProcessing,.CreateConnection,.ProcessRecord) for the session-creating cmdlets - Connection info assembly lives in
ConnectionInfoGenerator.cs - Progress reporting helper in
OperationProgressHelper.cs
- Single SDK-style csproj, target framework
-
PowerShell Script Module (
Posh-SSH/Posh-SSH.psm1)- ~35 PowerShell functions wrapping the binary cmdlets and the SSH.NET API directly
- Manages global session state via
$Global:SshSessionsand$Global:SFTPSessionsArrayLists - Pre-loads
Assembly/BouncyCastle.Cryptography.dllandAssembly/Renci.SshNet.dllviaAdd-Typeat the top of the file — this is what avoids assembly-resolution conflicts when something else in-process has a different Renci version loaded (e.g., Windows Server 2019 Storage Server's built-in copy)
Session and file-transfer:
New-SSHSession, New-SFTPSession, Get-SCPItem, Set-SCPItem, Get-SFTPItem, Set-SFTPItem, Get-SSHHostKey
Trusted host store backends:
New-SSHMemoryTrustedHostStore, Get-SSHJsonTrustedHostStore, Get-SSHOpenSSHTrustedHostStore
Trusted host management (C# rewrites from v3.x PowerShell originals):
New-SSHTrustedHost, Add-SSHTrustedHost, Get-SSHTrustedHost, Remove-SSHTrustedHost
Posh-SSH/Posh-SSH.psd1:
RequiredAssemblies = @('Assembly\Renci.SshNet.dll', 'Assembly\BouncyCastle.Cryptography.dll')NestedModules = @('PoshSSH.dll','Posh-SSH.psm1')Prereleaseis unset for stable releases; set it (e.g.'beta1') to publish a prerelease such as4.0.0-beta1
- Each session type (SSH/SFTP) has a dedicated ArrayList
- Sessions carry
SessionId(integer index),Host, and the underlying SSH.NET connection objects - Functions use parameter sets to accept either
SessionId(index) or session objects directly
.\Build-Module.ps1 # Release build + package + SHA256
.\Build-Module.ps1 -Configuration Debug # Debug build
.\Build-Module.ps1 -SkipBuild # Repackage existing DLL only
.\Build-Module.ps1 -OutputPath C:\Releases # Custom zip locationWhat the script does:
dotnet build -c $ConfigurationonSource/PoshSSH/PoshSSH.Core/PoshSSH.Core.csproj- Copies the netstandard2.0 build output to
Posh-SSH/PoshSSH.dll - Parses the manifest with
Test-ModuleManifest - Spawns a fresh
pwsh/powershelland verifies every cmdlet declared inCmdletsToExportactually loads (and warns if extras are exported) - Validates every
RequiredAssembliesandFileListentry exists on disk - Packages
Posh-SSH/intoPosh-SSH-{version}.zipand reports the SHA256
The cmdlet expectations are derived from the manifest itself — no hardcoded list — so cmdlet renames in Posh-SSH.psd1 flow through automatically.
.\Invoke-DocumentationBuild.ps1Requires the platyPS module. Converts docs/*.md to MAML help in Posh-SSH\en-US\ and refreshes the markdown from the loaded module.
The tests/ directory contains:
| File | Purpose |
|---|---|
Get-SSHSession.Tests.ps1, Remove-SSHSession.Tests.ps1 |
Pester unit tests for session-management functions |
Posh-SSH.Integration.Tests.ps1 |
Full integration suite against a live SSH server (password and key auth, multiple key formats) |
Run-IntegrationTests.ps1 |
Interactive launcher for the integration suite |
Setup-LinuxTestVm.sh |
Bash script that provisions a Linux VM with 12 test accounts covering password, RSA/Ed25519/ECDSA (multiple curves), encrypted keys, PKCS#1 PEM, multi-factor (AuthenticationMethods publickey,password), and forced keyboard-interactive — produces a bundled tarball with credentials and key files for cross-host testing |
README.md |
Author's notes on running the suite |
Run unit tests:
Invoke-Pester .\testsRun integration tests (requires live server + write access to /tmp):
$password = ConvertTo-SecureString "YourPassword" -AsPlainText -Force
.\tests\Posh-SSH.Integration.Tests.ps1 -ComputerName 192.168.1.100 -UserName testuser -Password $password
# or key-based:
.\tests\Posh-SSH.Integration.Tests.ps1 -ComputerName 192.168.1.100 -UserName testuser -KeyPath C:\Users\test\.ssh\id_rsaImport-Module .\Posh-SSH\Posh-SSH.psd1 -ForceFunctions consistently use two parameter sets:
Index:[Int32[]] $SessionIdSession/ComputerName: pass session objects or computer names directly
C# cmdlets use WriteError(), WriteWarning(), and WriteVerbose(). Progress reporting flows through OperationProgressHelper.cs.
Three backend implementations behind ITrustedHostStore:
MemoryTrustedHostStore— in-process, lost on session endJsonTrustedHostStore— persistent JSON at~/.poshssh/hosts.json(the v4.0 format supports multiple host keys per host — incompatible with v3.x; users upgrading should back up the file first)OpenSSHTrustedHostStore— reads/writes a standard OpenSSHknown_hostsfile
Legacy registry-based storage from v3.x converts via Convert-SSHRegistryToJsonTrustedHost.
- Module version lives in
Posh-SSH/Posh-SSH.psd1; prerelease tag inPrivateData.PSData.Prerelease - When modifying C# code, rebuild via
Build-Module.ps1(it copies the fresh DLL intoPosh-SSH/and re-validates the manifest) - PowerShell function changes can be tested immediately by
Import-Module .\Posh-SSH\Posh-SSH.psd1 -Force - The module supports a broad set of encryption methods, key exchange algorithms, and key formats — see
Readme.mdfor the full list - Format files in
Posh-SSH/Format/define custom output for session objects and SFTP files Source/PoshSSH/PoshSSH.Core/bin/andobj/are build artifacts;.gitignorekeepsSource/**/bin/**andSource/**/obj/**out of source control- Distribution zips (
Posh-SSH-*.zip) are gitignored