This article has not been completed yet. However, it may already contain helpful information and therefore it has been published at this stage.


Posh-SSH Module:

# Installing Posh Module
Write-Host "Installing the Posh-SSH Module" -ForegroundColor Green
install-module posh-ssh
# Show all available module commands
Write-Host "Listing all Posh-SSH - Commands..." -ForegroundColor Green
Get-Command -Module Posh-SSH
CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Function        Get-PoshSSHModVersion                              2.3.0      Posh-SSH
Function        Get-SFTPChildItem                                  2.3.0      Posh-SSH
Function        Get-SFTPContent                                    2.3.0      Posh-SSH
Function        Get-SFTPLocation                                   2.3.0      Posh-SSH
Function        Get-SFTPPathAttribute                              2.3.0      Posh-SSH
Function        Get-SFTPSession                                    2.3.0      Posh-SSH
Function        Get-SSHPortForward                                 2.3.0      Posh-SSH
Function        Get-SSHSession                                     2.3.0      Posh-SSH
Function        Get-SSHTrustedHost                                 2.3.0      Posh-SSH
Function        Invoke-SSHCommand                                  2.3.0      Posh-SSH
Function        Invoke-SSHCommandStream                            2.3.0      Posh-SSH
Function        Invoke-SSHStreamExpectAction                       2.3.0      Posh-SSH
Function        Invoke-SSHStreamExpectSecureAction                 2.3.0      Posh-SSH
Function        Invoke-SSHStreamShellCommand                       2.3.0      Posh-SSH
Function        Move-SFTPItem                                      2.3.0      Posh-SSH
Function        New-SFTPFileStream                                 2.3.0      Posh-SSH
Function        New-SFTPItem                                       2.3.0      Posh-SSH
Function        New-SFTPSymlink                                    2.3.0      Posh-SSH
Function        New-SSHDynamicPortForward                          2.3.0      Posh-SSH
Function        New-SSHLocalPortForward                            2.3.0      Posh-SSH
Function        New-SSHRemotePortForward                           2.3.0      Posh-SSH
Function        New-SSHShellStream                                 2.3.0      Posh-SSH
Function        New-SSHTrustedHost                                 2.3.0      Posh-SSH
Function        Remove-SFTPItem                                    2.3.0      Posh-SSH
Function        Remove-SFTPSession                                 2.3.0      Posh-SSH
Function        Remove-SSHSession                                  2.3.0      Posh-SSH
Function        Remove-SSHTrustedHost                              2.3.0      Posh-SSH
Function        Rename-SFTPFile                                    2.3.0      Posh-SSH
Function        Set-SFTPContent                                    2.3.0      Posh-SSH
Function        Set-SFTPLocation                                   2.3.0      Posh-SSH
Function        Set-SFTPPathAttribute                              2.3.0      Posh-SSH
Function        Start-SSHPortForward                               2.3.0      Posh-SSH
Function        Stop-SSHPortForward                                2.3.0      Posh-SSH
Function        Test-SFTPPath                                      2.3.0      Posh-SSH
Cmdlet          Get-SCPFile                                        2.3.0      Posh-SSH
Cmdlet          Get-SCPFolder                                      2.3.0      Posh-SSH
Cmdlet          Get-SCPItem                                        2.3.0      Posh-SSH
Cmdlet          Get-SFTPFile                                       2.3.0      Posh-SSH
Cmdlet          Get-SFTPItem                                       2.3.0      Posh-SSH
Cmdlet          New-SFTPSession                                    2.3.0      Posh-SSH
Cmdlet          New-SSHSession                                     2.3.0      Posh-SSH
Cmdlet          Set-SCPFile                                        2.3.0      Posh-SSH
Cmdlet          Set-SCPFolder                                      2.3.0      Posh-SSH
Cmdlet          Set-SCPItem                                        2.3.0      Posh-SSH
Cmdlet          Set-SFTPFile                                       2.3.0      Posh-SSH
Cmdlet          Set-SFTPFolder                                     2.3.0      Posh-SSH
Cmdlet          Set-SFTPItem                                       2.3.0      Posh-SSH
# Connecting to the SFTP - Server
Write-Host "Connecting..." -ForegroundColor Green
New-SFTPSession -Computername
# Creating a txt file on SFTP server
Write-Host "Creating file..." -ForegroundColor Green
New-SFTPItem -SessionId 0 -Path "/SFTP/tom/test2.txt" -ItemType file
# List subdirectory files  on SFTP server
Write-Host "Listing files..." -ForegroundColor Green
Get-SFTPChildItem -SessionId 0 -Path "/SFTP/tom/"
# Download file to client
Write-Host "Download file to client" -ForegroundColor Green
Get-SFTPFile -SessionId 0 -RemoteFile /SFTP/tom/Test.txt -LocalPath c:\temp
# Upload file to SFTP server
Write-Host "Upload file to SFTP server" -ForegroundColor Green
Set-SFTPFile -SessionId 0 -LocalFile c:\temp\TestIII.txt -RemotePath /SFTP/tom -Overwrite:$true


Installing the Assembly

First, you need to install the WinSCP .NET assembly. In most cases, all you need to do is download the package and extract it along with your PowerShell script.

cd c:\temp
# Install WinSCP Module
Install-Module -Name WinSCP
Get-Command -Module WinSCP
CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           Close-WinSCPSession                        WinSCP
Alias           Enter-WinSCPSession                        WinSCP
Alias           Exit-WinSCPSession                         WinSCP
Alias           Open-WinSCPSession                         WinSCP
Function        ConvertTo-WinSCPEscapedString              WinSCP
Function        Copy-WinSCPItem                            WinSCP
Function        Get-WinSCPChildItem                        WinSCP
Function        Get-WinSCPHostKeyFingerprint               WinSCP
Function        Get-WinSCPItem                             WinSCP
Function        Get-WinSCPItemChecksum                     WinSCP
Function        Get-WinSCPSession                          WinSCP
Function        Invoke-WinSCPCommand                       WinSCP
Function        Move-WinSCPItem                            WinSCP
Function        New-WinSCPItem                             WinSCP
Function        New-WinSCPItemPermission                   WinSCP
Function        New-WinSCPSession                          WinSCP
Function        New-WinSCPSessionOption                    WinSCP
Function        New-WinSCPTransferOption                   WinSCP
Function        New-WinSCPTransferResumeSupport            WinSCP
Function        Receive-WinSCPItem                         WinSCP
Function        Remove-WinSCPItem                          WinSCP
Function        Remove-WinSCPSession                       WinSCP
Function        Rename-WinSCPItem                          WinSCP
Function        Send-WinSCPItem                            WinSCP
Function        Start-WinSCPConsole                        WinSCP
Function        Sync-WinSCPPath                            WinSCP
Function        Test-WinSCPPath                            WinSCP
# Set credentials to a PSCredential Object.
$credential = Get-Credential
$sshHostKeyFingerprint = "ssh-ed25519 255 5c:ff:36:de:0e:ae:97:b7:4d:5d:90:51:3c:c3:f9:b3"
$sessionOption = New-WinSCPSessionOption -HostName localhost -SshHostKeyFingerprint $sshHostKeyFingerprint -Credential $credential
$session = New-WinSCPSession -SessionOption $sessionOption
# Using the WinSCPSession, download the file from the remote host to the local host.
Receive-WinSCPItem -WinSCPSession $session -Path "/SFTP/tom/TestIII.txt" -Destination "C:\temp\"
Get-WinSCPChildItem -WinSCPSession $session -Path "/SFTP/tom/"
Send-WinSCPItem -WinSCPSession $session -Path 'C:\temp\TestIII.txt' -Destination '/SFTP/tom/Test4.txt'
New-WinSCPItem -WinSCPSession $session -Path '/SFTP/tom/' -Name 'TextFile.txt' -ItemType File -Value 'Hello World!'
Close-WinSCPSession -WinSCPSession $session


WinSCP PowerShell Wrapper Module.
Using WinSCP .NET Assembly from PowerShell :: WinSCP
WinSCP is a free SFTP, SCP, Amazon S3, WebDAV, and FTP client for Windows.
SSH und SFTP mit der PowerShell
Building PowerShell Tools for MSPs: Using SFTP