Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Solaris Symphony Sdn Bhd @2018
- #powershell script for retrieving cisco router running config
- #load Posh-SSH module
- Import-Module Posh-SSH
- #Set the credentials
- $Password = ConvertTo-SecureString 'PASSWORD' -AsPlainText -Force
- $UserName = "USER"
- $Credential = New-Object System.Management.Automation.PSCredential ($UserName, $Password)
- #Set local file path
- $FilePath = ""
- $FileExtension = ".txt"
- #Set the IP of the SSH server
- $ServerIPs = 'IP' # IP List
- ForEach ($ServerIP in $ServerIPs)
- {
- #Establish the SSH connection
- New-SSHSession -ComputerName $ServerIP -Credential $Credential -Force
- $Stream = New-SSHShellStream -Index 0
- $Stream.write("terminal length 0`n") # disable more prompt
- $Stream.Write("show run`n") # display running config
- #wait for 10 second for command to complete
- Start-Sleep -Seconds 10
- $Result = $Stream.Read()
- #write output to file
- Write-Output $Result | Out-File $FilePath$ServerIP$FileExtension
- #delete ssh session
- Remove-SSHSession -Index 0 | Out-Null
- Start-Sleep -Seconds 5 #wait 5 second for next router
- }
Add Comment
Please, Sign In to add comment