title: How to redirect or retrieve the output of a telnet process ran by a Powershell script?
body: <p>I am running a Powershell script that starts a telnet process which will connect on a client machine and run a command. The client machine's operating system is a personalized version of VxWorks, and the command I'm using on the telnet calls a tool developed internally on the machine:</p>
  
  <pre><code>mediaGet("gei",1)
  </code></pre>
  
  <p>I'd like to retrieve the output of the code and log it.</p>
  
  <p>I've tried using the parameters -NoNewWindow and -RedirectStandardOutput on the Powershell script, but it only creates me an empty file which means it fails to retrieve the output.</p>
  
  <p>Here is the Powershell script:</p>
  
  <pre><code>Start-Process -FilePath 'telnet.exe' -ArgumentList '162.100.10.10'
  [system.reflection.assembly]::loadwithpartialname("System.Windows.Forms")
  $SendKeys = [System.Windows.Forms.SendKeys]
  $sendkeys::SendWait('mediaGet{(}"gei"{)},1')
  Start-Sleep -Seconds .5
  $sendkeys::SendWait("{ENTER}")
  Start-Sleep -Seconds .5
  $sendkeys::SendWait("exit{ENTER}")
  </code></pre>
  
  <p>(Credits of this code go to the selected answer of this question <a href="https://stackoverflow.com/questions/56130037/how-to-use-a-string-variable-as-a-telnet-command-in-a-vbscript">How to use a string variable as a telnet command in a vbscript?</a>)</p>
  
  <p>This is the output of the code</p>
  
  <pre><code>mediaGet("gei",1)
  &gt; media: 12345
  &gt; up: 1000 full duplex
  </code></pre>
  
  <p>I would like a text file at the end with the following lines:</p>
  
  <pre><code>media: 12345
  up: 1000 full duplex
  </code></pre>
  
  <p>How can I get there?</p>