This module is for Windows PowerShell 3.0 or above. It is compiled for .NET Framework 4.5.
Install-Module-Name Posh-SSH
Here’s a simple script that grabs credentials from a file. See this other article for more on password management. It uses the credentials to open a new SSH session to the remote computer and execute the pwd command and returns the results of that command. Then, it closes the SSH session.
There’s a lot of different tools out there to essentially SSH to a Linux host. They seem to come short when one needs to use secure copy. WinSCP has been around forever and is a relatively mature tool for doing SCP on a Windows client. My requirement is to copy files from a Linux server to a Windows client. WinSCP seems to be the best fit for my one need. Here are the general steps to getting it done:
First install WinSCP wrapper to enable use of SCP from PowerShell. Windows Management Framework 5.0 is a prerequisite.
Run the WinSCP application to collect the key from the target Linux host.
Generate credentials to be used by a script to copy files. Run a script to copy the files.
If needed, set up a scheduled task to run the copy script on an interval.
In PowerShell running as administrator, run the following:
Install-Module -Name WinSCP
Check the install by running the following:
Get-Command -Module WinSCP
Store credentials to be used in a later script. Save Password to File
$credential = Get-Credential
$credential.Password | ConvertFrom-SecureString | Set-Content G:\scripts\PasswordFile.txt
Run a script the uses the password file to access the Linux server and copy over your files. $session = New-WinSCPSession -Hostname <Linux Host> -Credential $credential -SshHostKeyFingerprint "ssh-rsa-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx"