Guest User

Untitled

a guest
Apr 12th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #Solaris Symphony Sdn Bhd @2018
  2. #powershell script for retrieving cisco router running config
  3. #load Posh-SSH module
  4. Import-Module Posh-SSH
  5.  
  6. #Set the credentials
  7. $Password = ConvertTo-SecureString 'PASSWORD' -AsPlainText -Force
  8. $UserName = "USER"
  9. $Credential = New-Object System.Management.Automation.PSCredential ($UserName, $Password)
  10.  
  11. #Set local file path
  12. $FilePath = ""
  13. $FileExtension = ".txt"
  14.  
  15. #Set the IP of the SSH server
  16. $ServerIPs = 'IP' # IP List
  17.  
  18. ForEach ($ServerIP in $ServerIPs)
  19. {
  20. #Establish the SSH connection
  21. New-SSHSession -ComputerName $ServerIP -Credential $Credential -Force
  22.  
  23. $Stream = New-SSHShellStream -Index 0
  24.  
  25. $Stream.write("terminal length 0`n") # disable more prompt
  26. $Stream.Write("show run`n") # display running config
  27.  
  28. #wait for 10 second for command to complete
  29. Start-Sleep -Seconds 10
  30. $Result = $Stream.Read()
  31.  
  32. #write output to file
  33. Write-Output $Result | Out-File $FilePath$ServerIP$FileExtension
  34.  
  35. #delete ssh session
  36. Remove-SSHSession -Index 0 | Out-Null
  37. Start-Sleep -Seconds 5 #wait 5 second for next router
  38. }
Add Comment
Please, Sign In to add comment