Cisco device output by Powershell script

Here is simple tip of How to retrieve Cisco device output by Powershell script

 

$User = "John"
$pw = "ipBalance"
$IP = "192.168.7.77"

#List of commands will be applied during logon/ssh.
#Below commands will be added on your codes.txt -> commands.txt.

echo "show config" >>code.txt
echo "show arp" >>code.txt
echo "show tech" >>code.txt
echo end >>code.txt
echo exit >>code.txt
 
#Converts the file to ASCII format (separate file)#
$lines = gc "code.txt"
$lines | out-file -encoding Ascii c:\tools\commands.txt
 

# Defining the plink command : 1. the cmd.exe call, 2. the command in cmd as an argument.
# Output file named with IP
$install_cmd = "cmd.exe"
$install_args = “/c `"c:\tools\plink.exe -ssh -v -l $User -pw $pw $IP -batch < c:\tools\commands.txt >> c:\tools\$IP`.txt`""
#Execute command and wait for exit
$PlinkCMD = [System.Diagnostics.Process]::Start("$install_cmd","$install_args")
$PlinkCMD.WaitForExit()

#Remove the files created earlier#
del c:\tools\code.txt
del c:\tools\commands.txt

 

Leave a Reply