HP Switch Backup config

Welcome Forums General PowerShell Q&A HP Switch Backup config

Viewing 2 reply threads
  • Author
    Posts
    • #244478
      Participant
      Topics: 1
      Replies: 1
      Points: 17
      Rank: Member

      Hi everbody,

      I am trying to write a script to backup the config from several HP switches and copy it to a ftp server.

      My problem is if I execute every command of the script one by one in the powershell it works and I get a txt file on the ftp server with the config in it. But if I run the whole script at once as a ps1 file the script runs and finishes but it does not execute the commands in the shell stream. I think I would have to send a return (execute) command in the shell stream after the command but I do not know how to do this in powershell. Here is my script:

      Function copyrunningConf{
      Param([String] $ip)
      New-SSHSession -ComputerName $ip -Credential (Get-Credential) -AcceptKey</p>
      $session = Get-SSHSession -ComputerName $ip
      $stream = New-SSHShellStream -Index $session.SessionID
      $stream.WriteLine(&quot;Conf T&quot;)
      $stream.WriteLine(&quot;Copy running-config tftp NOACTUALIP outtaNoida.txt pc&quot;)
      $result = $stream.Read()
      Write-Output $result
      Remove-SSHSession -Index 0
      }
      $ip = &quot;10.66.12.119&quot;
      copyrunningConf $ip

      So I think after the commands like conf t and Copy Running I would need to send a Return. Does anyone know how to do this and can help? I tried $stream.flush and $stream.writeLine(“\n”) and $stream.WriteLine(“`n”) but those commands did not work.

      With kind regards,

      Arnold

      • This topic was modified 2 months ago by NOID24.
      • This topic was modified 2 months ago by grokkit.
    • #245490
      Participant
      Topics: 0
      Replies: 38
      Points: 381
      Helping Hand
      Rank: Contributor

      Hello Arnold,
      Welcome to PowerShell.org
      Please read “Read Me Before Posting! You’ll be Glad You Did” and use proper formatting for your code.

      Have you tried Invoke-SSHCommand<!–more–>

      Hope that helps.

    • #245520
      Participant
      Topics: 1
      Replies: 1
      Points: 17
      Rank: Member

      Hi everbody,

      my mistake was that the script executes the commands too fast and does not wait till the previous command is finished.

      So between $stream.WriteLine("Copy running-config tftp NOACTUALIP outtaNoida.txt pc")

      and Remove-SSHSession -Index 0 I needed a Start-Sleep -s 5

      otherwise it kills the ssh-Session before the tftp copy command is finished. The sleep command gives the previous command the time it needs.

      With kind regards,

       

      Arnold

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