### Example 1: Download a file Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/Get-SCPItem.md This example demonstrates how to download the 'dmesg' file from a remote server to the current local directory using SCP. ```APIDOC ## Example 1: Download a file ### Description Download the 'dmesg' file from the remote server 192.168.1.169 to the current local directory. ### Command ```powershell Get-SCPItem -ComputerName 192.168.1.169 -Credential carlos -Path "/var/log/dmesg" -PathType File -Destination "./" ``` ``` -------------------------------- ### Install and Import Posh-SSH Module Source: https://context7.com/darkoperator/posh-ssh/llms.txt Installs the Posh-SSH module from the PowerShell Gallery for the current user and imports it into the session. Verifies the installed version. ```powershell # Install from PSGallery Install-Module -Name Posh-SSH -Scope CurrentUser # Import for use Import-Module Posh-SSH # Verify version Get-PoshSSHModVersion ``` -------------------------------- ### Example 2: Download a file with a new name Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/Get-SCPItem.md This example shows how to download the 'dmesg' file from a remote server and save it with a different name locally. ```APIDOC ## Example 2: Download a file with a new name ### Description Download the 'dmesg' file from the remote server 192.168.1.169 to the current local directory and rename it to 'dmesg_server_169'. ### Command ```powershell Get-SCPItem -ComputerName 192.168.1.169 -Credential carlos -Path "/var/log/dmesg" -PathType File -Destination "./" -NewName "dmesg_server_169" ``` ``` -------------------------------- ### Get SSH Host Key and Add to Trusted Hosts Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/Get-SSHHostKey.md This example demonstrates how to retrieve the host key for a server and immediately add it to the trusted hosts list using New-SSHTrustedHost. ```powershell PS C:\> 'server' | Get-SSHHostKey | New-SSHTrustedHost ``` -------------------------------- ### Install Posh-SSH Module Source: https://github.com/darkoperator/posh-ssh/blob/master/Readme.md To install the Posh-SSH module, run the following command in PowerShell. ```PowerShell Install-Module -Name Posh-SSH ``` -------------------------------- ### Create and Use In-Memory Known Host Store Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/New-SSHMemoryKnownHost.md This example demonstrates creating an in-memory known host store and adding a host entry to it. The store is then used to verify the added entry. ```powershell PS C:\> $inmem = New-SSHMemoryKnownHost PS C:\> New-SSHTrustedHost -KnownHostStore $inmem -HostName 192.168.1.165 -FingerPrint 3c:bf:26:9f:d9:63:d7:48:b8:fc:7b:32:e8:f9:5a:b4 -Name Pi True PS C:\> $inmem.GetAllKeys() HostName HostKeyName Fingerprint -------- ----------- ----------- 192.168.1.165 Pi 3c:bf:26:9f:d9:63:d7:48:b8:fc:7b:32:e8:f9:5a:b4 ``` -------------------------------- ### Create a Directory using New-SFTPItem Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/New-SFTPItem.md This example demonstrates how to create a directory named 'help' in the '/tmp/' path on the remote host using an existing SFTP session identified by SessionId 0. It then verifies the creation by retrieving the path attributes. ```powershell New-SFTPItem -SessionId 0 -Path /tmp/help -ItemType Directory FullName : /tmp/help LastAccessTime : 3/17/2015 7:58:11 PM LastWriteTime : 3/17/2015 7:58:11 PM Length : 6 UserId : 1000 PS C:\> Get-SFTPPathAttribute 0 -Path /tmp/help LastAccessTime : 3/17/2015 7:58:11 PM LastWriteTime : 3/17/2015 7:58:11 PM Size : 6 UserId : 1000 GroupId : 1000 IsSocket : False IsSymbolicLink : False IsRegularFile : False IsBlockDevice : False IsDirectory : True IsCharacterDevice : False IsNamedPipe : False OwnerCanRead : True OwnerCanWrite : True OwnerCanExecute : True GroupCanRead : True GroupCanWrite : True GroupCanExecute : True OthersCanRead : True OthersCanWrite : False OthersCanExecute : True Extensions : ``` -------------------------------- ### Create SFTP Session with Credentials Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/New-SFTPSession.md This example demonstrates how to create a new SFTP session to a remote host using provided credentials. The -Verbose parameter provides additional output during the connection process. ```powershell PS C:\> New-SFTPSession -ComputerName 192.168.1.155 -Credential (Get-Credential) -Verbose ``` -------------------------------- ### Get Current and Latest Posh-SSH Module Version Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/Get-PoshSSHModVersion.md Run this command to display the currently installed version of Posh-SSH and the latest available version from the repository. This is useful for determining if an update is needed. ```powershell Get-PoshSSHModVersion ``` -------------------------------- ### Download a folder using SessionId Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/Get-SFTPItem.md This example demonstrates how to download the '.ssh' folder from the remote server to the current local directory using a specified SessionId. The -Verbose parameter provides additional output during the operation. ```powershell PS C:\>Get-SFTPItem -SessionId 0 -Path .ssh -Destination ./ -Verbose ``` -------------------------------- ### Set SFTP Path Attribute - Make Executable Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/Set-SFTPPathAttribute.md This example demonstrates how to make a specific file executable by all users (owner, group, and others) using its SessionId and Path. Ensure the SessionId is valid and the Path exists on the remote server. ```powershell PS C:\> Set-SFTPPathAttribute -SessionId 0 -Path /usr/local/test_tools/dns_test.py -GroupCanExecute $true -OwnerCanExecute $true -OthersCanExecute $true ``` -------------------------------- ### Create a Dynamic Port Forward using Session ID Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/New-SSHDynamicPortForward.md This example demonstrates how to create a dynamic port forward using the SessionId parameter. Ensure you have an active SSH session with the specified SessionId. ```powershell New-SSHDynamicPortForward -BoundPort 8080 -SessionId 1 ``` -------------------------------- ### Download a file with a new name using SCP Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/Get-SCPItem.md This example demonstrates how to download a file from a remote server and save it with a different name in the local destination directory. This is useful for organizing downloaded files or avoiding name conflicts. ```powershell PS C:\> Get-SCPItem -ComputerName 192.168.1.169 -Credential carlos -Path "/var/log/dmesg" -PathType File -Destination ./ -NewName dmesg_server_169 ``` -------------------------------- ### Execute Command on Multiple SSH Sessions Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/Invoke-SSHCommand.md This example demonstrates executing a 'uname -a' command across multiple SSH sessions identified by their SessionIds. It shows the output and exit status for each host. ```powershell Invoke-SSHCommand -Command "uname -a" -SessionId 0,2,3 ``` -------------------------------- ### Start SSH Port Forwarding using SshSession Object Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/Start-SSHPortForward.md Establishes local port forwarding by directly using an SshSession object. This method is useful when you have the session object readily available. The specified BoundPort will listen for incoming connections and forward them to the BoundHost and port. ```powershell Start-SSHPortForward -SSHSession $sshsesssion -BoundPort 8080 -BoundHost localhost ``` -------------------------------- ### Create a Dynamic Port Forward using SSH Session Object Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/New-SSHDynamicPortForward.md This example shows how to create a dynamic port forward by passing an SSH session object directly to the -SSHSession parameter. This is useful when you have the SSH session object available. ```powershell New-SSHDynamicPortForward -BoundPort 8080 -SSHSession $sshsesssion ``` -------------------------------- ### Get-SCPItem - NoKey Authentication Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/Get-SCPItem.md This snippet shows the syntax for using Get-SCPItem with no specific key authentication, relying on default credentials or interactive prompts. It includes parameters for destination, path, path type, and optional parameters for renaming, path transformation, computer name, credentials, port, proxy settings, timeouts, and host key handling. ```APIDOC ## Get-SCPItem - NoKey (Default) ### Description Download from a remote server via SCP a file or directory using default or provided credentials without explicit key files. ### Syntax ```powershell Get-SCPItem -Destination -Path -PathType [-NewName ] [-PathTransformation ] [-ComputerName] [-Credential] [-Port ] [-ProxyServer ] [-ProxyPort ] [-ProxyCredential ] [-ProxyType ] [-ConnectionTimeout ] [-OperationTimeout ] [-KeepAliveInterval ] [-AcceptKey] [-Force] [-ErrorOnUntrusted] [-KnownHost ] [-ProgressAction ] [] ``` ### Parameters * **-Destination** (String) - Required - Path to the location where to download the item to. * **-Path** (String) - Required - The remote path of the file or directory to download. * **-PathType** (String) - Required - Specifies whether the remote path is a File or Directory. * **-NewName** (String) - Optional - A new name for the downloaded file or directory. * **-PathTransformation** (String) - Optional - Specifies how to transform the path. * **-ComputerName** (String[]) - Required - FQDN or IP Address of the host to establish an SSH connection. * **-Credential** (PSCredential) - Required - SSH Credentials to use for connecting to a server. If a key file is used, the password field is used for the Key pass phrase. * **-Port** (Int32) - Optional - The port number for the SSH connection. Default is 22. * **-ProxyServer** (String) - Optional - The proxy server address. * **-ProxyPort** (Int32) - Optional - The proxy server port. * **-ProxyCredential** (PSCredential) - Optional - Credentials for the proxy server. * **-ProxyType** (String) - Optional - The type of proxy server. * **-ConnectionTimeout** (Int32) - Optional - Connection timeout interval in seconds. Default is 10. * **-OperationTimeout** (Int32) - Optional - Operation timeout interval in seconds. * **-KeepAliveInterval** (Int32) - Optional - Keep alive interval in seconds. * **-AcceptKey** (SwitchParameter) - Optional - Automatically add the host key fingerprint to the list of trusted hosts. * **-Force** (SwitchParameter) - Optional - Overwrite existing files if they exist. Do not check the remote host fingerprint. * **-ErrorOnUntrusted** (SwitchParameter) - Optional - Raise an exception if the fingerprint is not trusted for the host. * **-KnownHost** (IStore) - Optional - A store for known host keys. * **-ProgressAction** (ActionPreference) - Optional - A common parameter for controlling progress display. ``` -------------------------------- ### Get-PoshSSHModVersion Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/Get-PoshSSHModVersion.md Retrieves the installed and latest versions of the Posh-SSH module. ```APIDOC ## Get-PoshSSHModVersion ### Description Gets the current installed version and the latest version of Posh-SSH. ### Syntax ```powershell Get-PoshSSHModVersion [-ProgressAction ] [] ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```powershell Get-PoshSSHModVersion ``` ### Response #### Success Response (200) Returns a PSObject containing the installed and current versions. - **InstalledVersion** (string) - The version of Posh-SSH currently installed. - **CurrentVersion** (string) - The latest available version of Posh-SSH. #### Response Example ```powershell InstalledVersion CurrentVersion ---------------- -------------- 1.7 1.6 ``` ``` -------------------------------- ### Get All SSH Sessions Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/Get-SSHSession.md Retrieves all active SSH sessions. This is the default behavior when no parameters are specified. ```powershell Get-SSHSession ``` -------------------------------- ### Create and Add Entry to JSON Known Host Store Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/Get-SSHJsonKnownHost.md Demonstrates creating a JSON known host store object using Get-SSHJsonKnownHost, adding a new host entry with SetKey, and then retrieving all entries with GetAllKeys. ```powershell $jsontest = Get-SSHJsonKnownHost -LocalFile .\test.json $jsontest.SetKey("192.168.1.1","Router","12:f8:7e:78:61:b4:bf:e2:de:24:15:96:4e:d4:72:53") True $jsontest.GetAllKeys() HostName HostKeyName Fingerprint -------- ----------- ----------- 192.168.1.1 Router 12:f8:7e:78:61:b4:bf:e2:de:24:15:96:4e:d4:72:53 ``` -------------------------------- ### Get SSH Registry Known Hosts Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/Get-SSHRegistryKnownHost.md Retrieves all known host entries from the Windows registry. ```APIDOC ## Get-SSHRegistryKnownHost ### Description Retrieves known host entries from the Windows registry. This is a read-only operation and is compatible with Windows environments. ### Method GET ### Endpoint /SSHRegistryKnownHost ### Parameters This cmdlet does not accept any parameters. ### Response #### Success Response (200) - **KnownHosts** (Array) - A list of known host entries. - **HostName** (String) - The hostname or IP address of the SSH server. - **Fingerprint** (String) - The SSH key fingerprint. - **Comment** (String) - An optional comment associated with the host entry. #### Response Example ```json { "KnownHosts": [ { "HostName": "example.com", "Fingerprint": "SHA256:abcdef123456...", "Comment": "Production server" }, { "HostName": "192.168.1.100", "Fingerprint": "SHA256:ghijkl789012...", "Comment": "Development machine" } ] } ``` ``` -------------------------------- ### Run Integration Tests using Helper Script Source: https://github.com/darkoperator/posh-ssh/blob/master/tests/README.md Simplify integration test execution with the provided helper script, supporting both password and key-based authentication. Ensure the script is executable. ```powershell # Password authentication .\tests\Run-IntegrationTests.ps1 -ComputerName "192.168.1.100" -UserName "testuser" -UsePassword ``` ```powershell # Key authentication .\tests\Run-IntegrationTests.ps1 -ComputerName "192.168.1.100" -UserName "testuser" -UseKey -KeyPath "C:\Users\test\.ssh\id_rsa" ``` -------------------------------- ### Get SSH Host Key for a Server Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/Get-SSHHostKey.md Use this command to retrieve the host key record for a specific server by its IP address. ```powershell PS C:\> Get-SSHHostKey -ComputerName 192.168.1.234 ``` -------------------------------- ### Get SSH Port Forwarding by Session ID Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/Get-SSHPortForward.md Use this command to retrieve port forwarding configurations when you have the SessionId of an active SSH connection. ```powershell Get-SSHPortForward -SessionId 1 ``` -------------------------------- ### Remove All SSH Sessions Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/Remove-SSHSession.md This example demonstrates how to remove all active SSH sessions by piping the output of Get-SSHSession to Remove-SSHSession. It returns True for each session removed. ```powershell Get-SSHSession | Remove-SSHSession True True ``` -------------------------------- ### Create SSH Session with Key-File Authentication Source: https://context7.com/darkoperator/posh-ssh/llms.txt Establishes an SSH connection using a private key file. Requires the key's passphrase to be provided securely. Throws an error if the host key is not trusted. ```powershell # --- Key-file authentication (passphrase in -Credential password field) --- $cred = New-Object PSCredential('admin', (ConvertTo-SecureString 'keyPassphrase' -AsPlainText -Force)) $session = New-SSHSession -ComputerName '10.0.1.50' ` -Credential $cred ` -KeyFile "$HOME/.ssh/id_ed25519" ` -ErrorOnUntrusted # throw if fingerprint not already trusted ``` -------------------------------- ### Get Remote Working Directory with Get-SFTPLocation Source: https://context7.com/darkoperator/posh-ssh/llms.txt Retrieve the current working directory on the remote SFTP server. This helps in understanding the context for relative paths. ```powershell Get-SFTPLocation -SessionId 0 ``` -------------------------------- ### Get SFTP File Content Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/Get-SFTPContent.md Retrieves the content of a file from an SFTP server using a session ID. The output is displayed as a string, which is the default behavior. ```powershell Get-SFTPContent -SessionId 0 -Path /etc/system-release ``` -------------------------------- ### Get Trusted Host Record from Registry Store Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/Get-SSHTrustedHost.md Retrieves the trusted host record for 'server1' from the registry known host store. Note that this store is deprecated. ```powershell PS C:\> Get-SSHTrustedHost -HostName 'server1' -KnownHostStore (Get-SSHRegistryKnownHost) ``` -------------------------------- ### Download Directory with Get-SFTPItem Source: https://context7.com/darkoperator/posh-ssh/llms.txt Use Get-SFTPItem to download an entire directory recursively. The -Force parameter overwrites existing items. ```powershell Get-SFTPItem -SessionId 0 -Path '/var/www/html' -Destination 'C:\Backups\' -Force -Verbose ``` -------------------------------- ### Get SSH Known Hosts and All Keys Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/Get-SSHOpenSSHKnownHost.md Retrieves known hosts from the default location and then displays all stored keys. This is useful for auditing or verifying host entries. ```powershell PS C:\> $SSHKnown = Get-SSHOpenSSHKnownHost PS C:\> $SSHKnown.GetAllKeys() HostName HostKeyName Fingerprint -------- ----------- ----------- 192.168.1.165 ecdsa-sha2-nistp256 3c:bf:26:9f:d9:63:d7:48:b8:fc:7b:32:e8:f9:5a:b4 ``` -------------------------------- ### Get All Available SFTP Sessions Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/Get-SFTPSession.md Call Get-SFTPSession without any parameters to list all currently active SFTP sessions. This is useful for checking the status of existing connections. ```powershell Get-SFTPSession SessionId Host Connected -------- ---- --------- 0 192.168.1.180 True ``` -------------------------------- ### Invoke-SSHCommand with Live Output and Error Handling Source: https://context7.com/darkoperator/posh-ssh/llms.txt Execute commands over SSH, displaying stdout in green and stderr in red. Includes an example of checking the ExitStatus for error handling. ```powershell Invoke-SSHCommand -Command 'apt-get update' -SessionId 0 ` -ShowStandardOutputStream -StandardOutputStreamColor Green ` -ShowErrorOutputStream -ErrorOutputStreamColor Red ``` ```powershell $r = Invoke-SSHCommand -Command 'cat /nonexistent' -SessionId 0 if ($r.ExitStatus -ne 0) { Write-Warning "Command failed on $($r.Host): exit $($r.ExitStatus)" } ``` -------------------------------- ### New-SFTPSession - Key Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/New-SFTPSession.md Creates an SFTP session using a private key file for authentication. ```APIDOC ## New-SFTPSession - Key ### Description Creates an SFTP session using a private key file for authentication. The password in the credentials parameter is used as the passphrase for the key file. ### Method ```powershell New-SFTPSession ``` ### Parameters #### Path Parameters - **ComputerName** (String[]) - Required - FQDN or IP Address of host to establish a SFTP Session. - **Credential** (PSCredential) - Required - SSH Credentials to use for connecting to a server. The password field is used for the Key passphrase. - **KeyFile** (String) - Required - Path to the private key file for authentication. #### Query Parameters - **Port** (Int32) - Optional - SSH TCP Port number to use for the SFTP connection. Default: 22 - **ProxyServer** (String) - Optional - Proxy server name or IP Address to use for connection. - **ProxyPort** (Int32) - Optional - Port to connect to on proxy server to route connection. Default: 8080 - **ProxyCredential** (PSCredential) - Optional - PowerShell Credential Object with the credentials for use to connect to proxy server if required. - **ProxyType** (String) - Optional - Type of Proxy being used (HTTP, Socks4 or Socks5). Default: HTTP - **ConnectionTimeout** (Int32) - Optional - Connection timeout interval in seconds. Default: 10 - **OperationTimeout** (Int32) - Optional - Operation timeout interval in seconds. Zero or below disables timeout. Default: 0 - **KeepAliveInterval** (Int32) - Optional - Keep Alive interval in seconds for a connection. Default: 10 - **AcceptKey** - Optional - Accepts the SSH host key if it is not found in the known hosts file. - **Force** - Optional - Suppresses confirmation prompts. - **ErrorOnUntrusted** - Optional - Throws an error if the SSH host key is untrusted. #### Request Example ```powershell $cred = Get-Credential New-SFTPSession -ComputerName 192.168.1.155 -Credential $cred -KeyFile "C:\path\to\your\private_key.pem" ``` ``` -------------------------------- ### Rename SFTP File using Session ID Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/Rename-SFTPFile.md Use this example to rename a remote file when you have the SFTP session ID. The -Verbose parameter provides feedback on the operation. ```powershell Rename-SFTPFile -SessionId 0 -Path /tmp/anaconda-ks.cfg -NewName anaconda-ks.cfg.old -Verbose VERBOSE: Renaming /tmp/anaconda-ks.cfg to anaconda-ks.cfg.old VERBOSE: File renamed ``` -------------------------------- ### New-SFTPSession: Create SFTP Session Source: https://context7.com/darkoperator/posh-ssh/llms.txt Establishes an SFTP subsystem connection. Supports password and key-file authentication, similar to New-SSHSession. Includes options for operation timeout and accepting host keys. Shows how to list and remove SFTP sessions. ```powershell # Password auth $sftp = New-SFTPSession -ComputerName 'fileserver.corp.local' ` -Credential (Get-Credential) -AcceptKey ``` ```powershell # Key-file auth $cred = New-Object PSCredential('deploy', (ConvertTo-SecureString '' -AsPlainText -Force)) $sftp = New-SFTPSession -ComputerName '10.0.2.20' ` -Credential $cred ` -KeyFile "$HOME/.ssh/deploy_rsa" ` -OperationTimeout 120 ` -AcceptKey ``` ```powershell # List open SFTP sessions Get-SFTPSession ``` ```powershell # Disconnect Remove-SFTPSession -SessionId $sftp.SessionId ``` -------------------------------- ### Download File with Get-SCPItem Source: https://context7.com/darkoperator/posh-ssh/llms.txt Download a file from a remote host using SCP. This cmdlet opens and closes its own connection. Use -AcceptKey for key-based authentication. ```powershell Get-SCPItem -ComputerName '10.0.1.50' -Credential (Get-Credential) ` -Path '/var/log/nginx/access.log' -PathType File ` -Destination 'C:\Logs\' -AcceptKey ``` -------------------------------- ### Get SSH Port Forwarding by SshSession Object Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/Get-SSHPortForward.md This command retrieves port forwarding configurations using the SshSession object. This is useful when you have the session object readily available. ```powershell Get-SSHPortForward -SSHSession $sshsess ``` -------------------------------- ### List Active SSH Sessions Source: https://context7.com/darkoperator/posh-ssh/llms.txt Retrieves and displays all currently active SSH session objects. Can be used to get a specific session object for use in other cmdlets like Invoke-SSHCommand. ```powershell # List all sessions Get-SSHSession # Get a specific session object for pipeline use $s = Get-SSHSession -SessionId 1 Invoke-SSHCommand -Command 'hostname' -SSHSession $s ``` -------------------------------- ### New-SFTPSession - KeyString Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/New-SFTPSession.md Creates an SFTP session using a private key as a string for authentication. ```APIDOC ## New-SFTPSession - KeyString ### Description Creates an SFTP session using a private key provided as a string for authentication. The password in the credentials parameter is used as the passphrase for the key string. ### Method ```powershell New-SFTPSession ``` ### Parameters #### Path Parameters - **ComputerName** (String[]) - Required - FQDN or IP Address of host to establish a SFTP Session. - **Credential** (PSCredential) - Required - SSH Credentials to use for connecting to a server. The password field is used for the Key passphrase. - **KeyString** (String[]) - Required - The private key content as a string array. #### Query Parameters - **Port** (Int32) - Optional - SSH TCP Port number to use for the SFTP connection. Default: 22 - **ProxyServer** (String) - Optional - Proxy server name or IP Address to use for connection. - **ProxyPort** (Int32) - Optional - Port to connect to on proxy server to route connection. Default: 8080 - **ProxyCredential** (PSCredential) - Optional - PowerShell Credential Object with the credentials for use to connect to proxy server if required. - **ProxyType** (String) - Optional - Type of Proxy being used (HTTP, Socks4 or Socks5). Default: HTTP - **ConnectionTimeout** (Int32) - Optional - Connection timeout interval in seconds. Default: 10 - **OperationTimeout** (Int32) - Optional - Operation timeout interval in seconds. Zero or below disables timeout. Default: 0 - **KeepAliveInterval** (Int32) - Optional - Keep Alive interval in seconds for a connection. Default: 10 - **AcceptKey** - Optional - Accepts the SSH host key if it is not found in the known hosts file. - **Force** - Optional - Suppresses confirmation prompts. - **ErrorOnUntrusted** - Optional - Throws an error if the SSH host key is untrusted. #### Request Example ```powershell $cred = Get-Credential $keyContent = Get-Content -Path "C:\path\to\your\private_key.pem" -Raw New-SFTPSession -ComputerName 192.168.1.155 -Credential $cred -KeyString $keyContent ``` ``` -------------------------------- ### Get Trusted Host Record from Default Store Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/Get-SSHTrustedHost.md Retrieves the trusted host record for 'server1' from the default known host store. This is useful for checking if a host is already trusted. ```powershell PS C:\> Get-SSHTrustedHost -HostName 'server1' ``` -------------------------------- ### New-SFTPSession - NoKey Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/New-SFTPSession.md Creates an SFTP session using username and password authentication. ```APIDOC ## New-SFTPSession - NoKey ### Description Creates an SFTP session using username and password authentication. ### Method ```powershell New-SFTPSession ``` ### Parameters #### Path Parameters - **ComputerName** (String[]) - Required - FQDN or IP Address of host to establish a SFTP Session. - **Credential** (PSCredential) - Required - SSH Credentials to use for connecting to a server. If a key file is used the password field is used for the Key passphrase. #### Query Parameters - **Port** (Int32) - Optional - SSH TCP Port number to use for the SFTP connection. Default: 22 - **ProxyServer** (String) - Optional - Proxy server name or IP Address to use for connection. - **ProxyPort** (Int32) - Optional - Port to connect to on proxy server to route connection. Default: 8080 - **ProxyCredential** (PSCredential) - Optional - PowerShell Credential Object with the credentials for use to connect to proxy server if required. - **ProxyType** (String) - Optional - Type of Proxy being used (HTTP, Socks4 or Socks5). Default: HTTP - **ConnectionTimeout** (Int32) - Optional - Connection timeout interval in seconds. Default: 10 - **OperationTimeout** (Int32) - Optional - Operation timeout interval in seconds. Zero or below disables timeout. Default: 0 - **KeepAliveInterval** (Int32) - Optional - Keep Alive interval in seconds for a connection. Default: 10 - **AcceptKey** - Optional - Accepts the SSH host key if it is not found in the known hosts file. - **Force** - Optional - Suppresses confirmation prompts. - **ErrorOnUntrusted** - Optional - Throws an error if the SSH host key is untrusted. #### Request Example ```powershell New-SFTPSession -ComputerName 192.168.1.155 -Credential (Get-Credential) ``` ``` -------------------------------- ### Get SFTP Location by Session ID Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/Get-SFTPLocation.md Retrieves the current SFTP working directory using a session ID. Ensure the session ID corresponds to an active SFTP connection. ```powershell PS C:\> Get-SFTPLocation -SessionId 0 /home/carlos ``` -------------------------------- ### New-SFTPItem Source: https://context7.com/darkoperator/posh-ssh/llms.txt Creates a new directory or an empty file on the remote SFTP server. ```APIDOC ## New-SFTPItem ### Description Creates a new directory or an empty file on the remote SFTP server. ### Method POST (implied) ### Endpoint SFTP Server ### Parameters #### Path Parameters - **SessionId** (int) - Required - The ID of the SFTP session. - **Path** (string) - Required - The remote path for the new item. - **ItemType** (string) - Required - The type of item to create ('Directory' or 'File'). ``` -------------------------------- ### Create SSH Session with Password Authentication Source: https://context7.com/darkoperator/posh-ssh/llms.txt Establishes an SSH connection using password authentication with interactive credential prompt. Automatically trusts unknown host keys. Sets connection and keep-alive timeouts. ```powershell # --- Password authentication (interactive credential prompt) --- $session = New-SSHSession -ComputerName 'webserver01.corp.local' ` -Credential (Get-Credential) ` -Port 22 ` -ConnectionTimeout 15 ` -KeepAliveInterval 30 ` -AcceptKey # auto-trust unknown host key on first connect ``` -------------------------------- ### New-SFTPSession Source: https://context7.com/darkoperator/posh-ssh/llms.txt Establishes an SFTP subsystem connection. It accepts standard SSH authentication and proxy options, along with an `-OperationTimeout` for per-operation limits. ```APIDOC ### New-SFTPSession — Create an SFTP session Establishes an SFTP subsystem connection. Accepts the same authentication and proxy options as `New-SSHSession`, plus `-OperationTimeout` for per-operation limits. ### Method ```powershell New-SFTPSession -ComputerName [-Credential ] [-KeyFile ] [-OperationTimeout ] [] ``` ### Parameters #### ComputerName (string) The hostname or IP address of the SFTP server. #### Credential (PSCredential) The user credentials for authentication. #### KeyFile (string) The path to the private key file for key-based authentication. #### OperationTimeout (int) The time-out in seconds for SFTP operations. #### AcceptKey (switch) Automatically accept the SSH host key. ### Request Example ```powershell # Password auth $sftp = New-SFTPSession -ComputerName 'fileserver.corp.local' ` -Credential (Get-Credential) -AcceptKey # Key-file auth $cred = New-Object PSCredential('deploy', (ConvertTo-SecureString '' -AsPlainText -Force)) $sftp = New-SFTPSession -ComputerName '10.0.2.20' ` -Credential $cred ` -KeyFile "$HOME/.ssh/deploy_rsa" ` -OperationTimeout 120 ` -AcceptKey # List open SFTP sessions Get-SFTPSession # Disconnect Remove-SFTPSession -SessionId $sftp.SessionId ``` ``` -------------------------------- ### Get SFTP Child Items by Session ID Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/Get-SFTPChildItem.md Retrieves all items in the root directory of an SFTP session identified by its SessionId. This is useful for a general overview of the SFTP server's contents. ```powershell Get-SFTPChildItem -SessionId 0 ``` -------------------------------- ### Create SSH Session with Credentials Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/New-SSHSession.md Use this command to establish a new SSH session to a specified server using provided credentials. The -Verbose parameter provides detailed output during the connection process. ```powershell PS C:\> New-SSHSession -ComputerName 192.168.1.234 -Credential (Get-Credential) -Verbose ``` -------------------------------- ### Get-SFTPChildItem: List Remote Directory Contents Source: https://context7.com/darkoperator/posh-ssh/llms.txt Enumerates files and directories on an SFTP server. Supports recursive listing, filtering by type (file/directory), and name globbing. Shows example output format. ```powershell # List current (home) directory Get-SFTPChildItem -SessionId 0 ``` ```powershell # List a specific path, files only, recursively Get-SFTPChildItem -SessionId 0 -Path '/var/www/html' -Recurse -File ``` ```powershell # Filter by name pattern Get-SFTPChildItem -SessionId 0 -Path '/etc' -Name '*.conf' ``` -------------------------------- ### Start-SSHPortForward (SessionId) Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/Start-SSHPortForward.md Initiates a local port forward using a SessionId to identify the SSH connection. ```APIDOC ## Start-SSHPortForward (SessionId) ### Description Establishes a local port forward using a SessionId to identify the SSH connection. ### Method Start-SSHPortForward ### Parameters #### Path Parameters - **SessionId** (Int32) - Required - The ID of the SSH session. - **BoundPort** (Int32) - Required - The local port to bind to. - **BoundHost** (String) - Required - The local host to bind to. ### Request Example ```powershell Start-SSHPortForward -SessionId 1 -BoundPort 8080 -BoundHost localhost ``` ### Response This cmdlet does not return a value. ``` -------------------------------- ### Start-SSHPortForward (SSHSession) Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/Start-SSHPortForward.md Initiates a local port forward using an SshSession object to identify the SSH connection. ```APIDOC ## Start-SSHPortForward (SSHSession) ### Description Establishes a local port forward using an SshSession object to identify the SSH connection. ### Method Start-SSHPortForward ### Parameters #### Path Parameters - **SSHSession** (SshSession) - Required - The SSH session object. - **BoundPort** (Int32) - Required - The local port to bind to. - **BoundHost** (String) - Required - The local host to bind to. ### Request Example ```powershell $session = New-SSHSession -ComputerName "server.example.com" -Credential (Get-Credential) Start-SSHPortForward -SSHSession $session -BoundPort 8080 -BoundHost localhost ``` ### Response This cmdlet does not return a value. ``` -------------------------------- ### Download Directory with Get-SCPItem Source: https://context7.com/darkoperator/posh-ssh/llms.txt Download an entire directory from a remote host using SCP. The -Force parameter is used to overwrite existing items at the destination. ```powershell Get-SCPItem -ComputerName '10.0.1.50' -Credential (Get-Credential) ` -Path '/etc/nginx' -PathType Directory ` -Destination 'C:\Backups\' -AcceptKey -Force ``` -------------------------------- ### New-SFTPSession Parameters Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/New-SFTPSession.md This snippet outlines the parameters available for the New-SFTPSession cmdlet, including options for host key validation and authentication. ```APIDOC ## New-SFTPSession ### Description Establishes a new SFTP session. ### Parameters #### Switch Parameters - **AcceptKey** Automatically accepts a new SSH fingerprint for a host. ```yaml Type: SwitchParameter Parameter Sets: (All) Aliases: Required: False Position: Named Default value: False Accept pipeline input: True (ByPropertyName) Accept wildcard characters: False ``` - **Force** Do not perform any host key validation of the host. ```yaml Type: SwitchParameter Parameter Sets: (All) Aliases: Required: False Position: Named Default value: False Accept pipeline input: True (ByPropertyName) Accept wildcard characters: False ``` - **ErrorOnUntrusted** Throw a terminating error if the host key is not a trusted one. ```yaml Type: SwitchParameter Parameter Sets: (All) Aliases: Required: False Position: Named Default value: False Accept pipeline input: True (ByPropertyName) Accept wildcard characters: False ``` #### String Parameters - **KeyFile** OpenSSH format SSH private key file. ```yaml Type: String Parameter Sets: Key Aliases: Required: False Position: Named Default value: None Accept pipeline input: True (ByPropertyName) Accept wildcard characters: False ``` - **KeyString** OpenSSH key in a string array to be used for authentication. ```yaml Type: String[] Parameter Sets: KeyString Aliases: Required: False Position: Named Default value: None Accept pipeline input: True (ByPropertyName) Accept wildcard characters: False ``` #### Object Parameters - **KnownHost** Known Host IStore either from New-SSHMemoryKnownHost, Get-SSHJsonKnownHost or Get-SSHOpenSSHKnownHost. ```yaml Type: IStore Parameter Sets: (All) Aliases: Required: False Position: Named Default value: None Accept pipeline input: False Accept wildcard characters: False ``` #### Other Parameters - **ProgressAction** {{ Fill ProgressAction Description }} ```yaml Type: ActionPreference Parameter Sets: (All) Aliases: proga Required: False Position: Named Default value: None Accept pipeline input: False Accept wildcard characters: False ``` ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ### INPUTS System.String[] System.Management.Automation.PSCredential System.Int32 System.String System.Boolean ### OUTPUTS ### NOTES ### RELATED LINKS ``` -------------------------------- ### Get SFTP Path Attributes by Session ID Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/Get-SFTPPathAttribute.md Use this to retrieve attributes for a specific path using an existing SFTP session ID. Ensure the session ID is valid and the path exists on the SFTP server. ```powershell Get-SFTPPathAttribute -SessionId 0 -Path "/tmp" ``` -------------------------------- ### Get-SCPItem Parameters Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/Get-SCPItem.md Details the parameters for the Get-SCPItem cmdlet, including their types, requirements, and descriptions. ```APIDOC ## Get-SCPItem ### Description Retrieves an item from a remote host using SCP. ### Parameters #### Path Parameters - **Path** (String) - Required - Path to item on the remote host to download. - **PathType** (String) - Required - What type of Item you are getting from the remote host via SCP. Accepted values: File, Directory #### Query Parameters - **NewName** (String) - Optional - New name for the item on the destination path. - **OperationTimeout** (Int32) - Optional - Timeout for execution of an operation. Zero or below disables timeout. Default value: 0 - **Port** (Int32) - Optional - SSH TCP Port number to use for the SSH connection. Default value: 22 - **ProxyCredential** (PSCredential) - Optional - PowerShell Credential Object with the credentials for use to connect to proxy server if required. - **ProxyPort** (Int32) - Optional - Port to connect to on proxy server to route connection. Default value: 8080 - **ProxyServer** (String) - Optional - Proxy server name or IP Address to use for connection. - **ProxyType** (String) - Optional - Type of Proxy being used (HTTP, Socks4 or Socks5). Default value: HTTP - **KeepAliveInterval** (Int32) - Optional - Sets a timeout interval in seconds after which if no data has been received from the server, session will send a message through the encrypted channel to request a response from the server. Default value: 10 - **KnownHost** (IStore) - Optional - Known Host IStore either from New-SSHMemoryKnownHost, Get-SSHJsonKnownHost or Get-SSHOpenSSHKnownHost. - **PathTransformation** (String) - Optional - Remote Path transormation to use. - **ProgressAction** (ActionPreference) - Optional - {{ Fill ProgressAction Description }} ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ### INPUTS System.String[] System.Management.Automation.PSCredential System.Int32 System.String System.Boolean System.Management.Automation.SwitchParameter ### OUTPUTS System.Object ### NOTES ### RELATED LINKS ``` -------------------------------- ### Get-SCPItem - Key Authentication Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/Get-SCPItem.md This snippet details the syntax for using Get-SCPItem with SSH private key authentication. It requires specifying the path to the private key file. Other parameters are similar to the NoKey authentication method. ```APIDOC ## Get-SCPItem - Key Authentication ### Description Download from a remote server via SCP a file or directory using an SSH private key file for authentication. ### Syntax ```powershell Get-SCPItem -Destination -Path -PathType [-NewName ] [-PathTransformation ] [-ComputerName] [-Credential] [-Port ] [-ProxyServer ] [-ProxyPort ] [-ProxyCredential ] [-ProxyType ] [-KeyFile ] [-ConnectionTimeout ] [-OperationTimeout ] [-KeepAliveInterval ] [-AcceptKey] [-Force] [-ErrorOnUntrusted] [-KnownHost ] [-ProgressAction ] [] ``` ### Parameters * **-Destination** (String) - Required - Path to the location where to download the item to. * **-Path** (String) - Required - The remote path of the file or directory to download. * **-PathType** (String) - Required - Specifies whether the remote path is a File or Directory. * **-NewName** (String) - Optional - A new name for the downloaded file or directory. * **-PathTransformation** (String) - Optional - Specifies how to transform the path. * **-ComputerName** (String[]) - Required - FQDN or IP Address of the host to establish an SSH connection. * **-Credential** (PSCredential) - Required - SSH Credentials to use for connecting to a server. If a key file is used, the password field is used for the Key pass phrase. * **-Port** (Int32) - Optional - The port number for the SSH connection. Default is 22. * **-ProxyServer** (String) - Optional - The proxy server address. * **-ProxyPort** (Int32) - Optional - The proxy server port. * **-ProxyCredential** (PSCredential) - Optional - Credentials for the proxy server. * **-ProxyType** (String) - Optional - The type of proxy server. * **-KeyFile** (String) - Optional - OpenSSH format SSH private key file. * **-ConnectionTimeout** (Int32) - Optional - Connection timeout interval in seconds. Default is 10. * **-OperationTimeout** (Int32) - Optional - Operation timeout interval in seconds. * **-KeepAliveInterval** (Int32) - Optional - Keep alive interval in seconds. * **-AcceptKey** (SwitchParameter) - Optional - Automatically add the host key fingerprint to the list of trusted hosts. * **-Force** (SwitchParameter) - Optional - Overwrite existing files if they exist. Do not check the remote host fingerprint. * **-ErrorOnUntrusted** (SwitchParameter) - Optional - Raise an exception if the fingerprint is not trusted for the host. * **-KnownHost** (IStore) - Optional - A store for known host keys. * **-ProgressAction** (ActionPreference) - Optional - A common parameter for controlling progress display. ``` -------------------------------- ### Get SFTP Path Information by Session ID Source: https://github.com/darkoperator/posh-ssh/blob/master/docs/Get-SFTPPathInformation.md Use this command to retrieve filesystem details for a specific path using an existing SFTP session identified by its ID. Ensure the SessionId and Path parameters are correctly provided. ```powershell Get-SFTPPathInformation -SessionId 0 -Path "/tmp" ``` -------------------------------- ### Upload file with key-file authentication (verbose) Source: https://context7.com/darkoperator/posh-ssh/llms.txt Uploads a file using SCP with key-file authentication. Requires a PSCredential object and specifies the key file path. Use -Verbose to see connection and upload details. ```powershell $cred = New-Object PSCredential('deploy', (ConvertTo-SecureString 'passphrase' -AsPlainText -Force)) Set-SCPItem -ComputerName 'prod-app01' -Credential $cred \ -KeyFile "$HOME/.ssh/deploy_rsa" \ -Path '. est.txt' -Destination '/var/www/html' \ -AcceptKey -Verbose ```