PSCP and Powershell

I have a script that I need to add to copy the Syslog from Linux. When I use PSCP.exe for this it works perfectly unless the RSA is unknown.

When the RSA key is known this works perfectly.

cmd.exe /c pscp -pw 12345678 -P 22 root@ $file

I get the following error when the RSA isn’t known and locks the script.

cmd.exe : The server’s host key is not cached in the registry. You

  • CategoryInfo : NotSpecified: (The server’s ho…e registry. You:String) , RemoteException
  • FullyQualifiedErrorId : NativeCommandError
    have no guarantee that the server is the computer you
    think it is.
    The server’s ssh-ed25519 key fingerprint is:
    If you trust this host, enter “y” to add the key to
    PuTTY’s cache and carry on connecting.
    If you want to carry on connecting just once, without
    adding the key to the cache, enter “n”.
    If you do not trust this host, press Return to abandon the

I can add the -batch switch at the script will keep running, but everything I have tried will not automate a yes, or ask for a yes or no.

Here is the full portion of the script.

#Prompt for IP</code> <code>$LinuxIP = read-host -prompt "Linux IP"</code> <code>if(Test-Connection $LinuxIP -Count 1 -Quiet){</code> <code>$status='True'</code> <code>Write-Host $LinuxIP is Online -ForegroundColor Green</code> <code>cmd.exe /c pscp -pw 123456 -P 22 -batch "root@${LinuxIP}:/var/log/syslog" ".\Files\AS"</code> <code>}else{$status='False'</code> <code>Write-Host $LinuxIP is Offline -ForegroundColor Red</code> <code>}

Is this possible in Powershell Version : 5.1.19041.610?

This isn’t really Powershell, it’s Powershell running CMD running a EXE. There are some folks putting ‘echo y’ in front of the command:

The better approach would ensuring all of the registry information is inserted to ensure the RSA is known, if that is a choice. Many of these prompts are asking to subvert built in command security, so what security components need to exist and be in place for the command to execute with the security measures in place?

This script as a whole pulls data from a testing lab that the Linux OS is reimaged often. There isn’t a worry about a man in the middle attack, just a worry about my scripting skills, lol. Upon request, PC information is needed from the Windows PCs and a few logs are needed off the Linux boxes. The script works great and gets all the needed information off Windows. I currently have a batch file that grabs all the Linux PCs info but was trying to get it all to work in one Powershell script, but every time the RSA key is reset the Powershell script fails and I revert back to the batch file.

I tried the “echo y”, but was unable to get it to work.

Using a cmd exe file makes it more difficult. Have you looked at using native Powershell modules like this:

Looks great I’ll try it thanks!!