PSCP and Powershell

Welcome Forums General PowerShell Q&A PSCP and Powershell

Viewing 2 reply threads
  • Author
    Posts
    • #276078
      Participant
      Topics: 2
      Replies: 3
      Points: 32
      Rank: Member

      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@10.10.10.10:/var/log/syslog $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:
      ssh-ed25519
      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
      connection.

      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&lt;/code&gt;<br />&lt;code&gt;$LinuxIP = read-host -prompt "Linux IP"&lt;/code&gt;<br />&lt;code&gt;if(Test-Connection $LinuxIP -Count 1 -Quiet){&lt;/code&gt;<br />&lt;code&gt;$status='True'&lt;/code&gt;<br />&lt;code&gt;Write-Host $LinuxIP is Online -ForegroundColor Green&lt;/code&gt;<br />&lt;code&gt;cmd.exe /c pscp -pw 123456 -P 22 -batch "[email protected]${LinuxIP}:/var/log/syslog" ".\Files\AS"&lt;/code&gt;<br />&lt;code&gt;}else{$status='False'&lt;/code&gt;<br />&lt;code&gt;Write-Host $LinuxIP is Offline -ForegroundColor Red&lt;/code&gt;<br />&lt;code&gt;}`

      Is this possible in Powershell Version : 5.1.19041.610?

      • This topic was modified 1 month, 2 weeks ago by Titus_Polo47.
    • #276297
      Participant
      Topics: 17
      Replies: 1951
      Points: 3,987
      Helping Hand
      Rank: Community Hero

      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:

      https://stackoverflow.com/questions/13598996/putty-wont-cache-the-keys-to-access-a-server-when-run-script-in-hudson

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

      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?

      • #276339
        Participant
        Topics: 2
        Replies: 3
        Points: 32
        Rank: Member

        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.

    • #276366
      Participant
      Topics: 17
      Replies: 1951
      Points: 3,987
      Helping Hand
      Rank: Community Hero

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

      https://mcpmag.com/articles/2018/07/19/transfer-files-via-scp-with-powershell.aspx

      • #276561
        Participant
        Topics: 2
        Replies: 3
        Points: 32
        Rank: Member

        Looks great I’ll try it thanks!!

Viewing 2 reply threads
  • You must be logged in to reply to this topic.