Forum Discussion
Retrieving information from multiple Access Points via PowerShell
fstorer Hello, you got that as once you run the read from the stream you reset the variable to no data.
I've tested this saving the read output to a new Variable and it is working for me, please test it and let me know the outcome.
$session = New-SSHSession -ComputerName $AP.IP -Credential $Credentials -AcceptKey
$SSHStream = New-SSHShellStream -SessionId $session.SessionId
$SSHStream.WriteLine("show interface")
$OutputVar = $null
$OutputVar = $($SSHStream.read())
$OutputVar
$OutputVar | Out-File -FilePath "$WorkingDir\APInterfaces.txt" -Encoding utf8
Regards
Erick Moreno
Thank you for your reply!
I managed to make it work, but I had to add the "Start-Sleep" command between the WriteLine and the SSHStream.read, otherwise it didn't work. So here is the script that worked for me:
- MadhurimaSep 06, 2021Copper Contributor
Dear @Erick A. Moreno R
Thank you for the above script. It was insightful and helped me achieved a goal.
I'm at present working on another project where I have automated the script using kshell. But now I'm trying run the script from Windows PowerShell.
Below is the script:
#! /bin/ksh
Variable= install_dir/xyz.cfg
Export Variable
$install_dir/pmgr -i $install_dir/abc/init.cfg
echo "application started"
Sleep 2
Ps - ef|grep pmgr
Echo $!
In PowerShell, I'm able to check the status of the application using invoke-sshcommand -sessionid 0 -command "ps -ef|grep pmgr
It gives the status of the application, but need to start the service using PowerShell. Could you please help?