title: Fetch line starting with a specific string in powershell
body: <p>I am executing a command for which I am getting output like below</p>
  <pre><code>Identifier:  3    SFP
  Connector:   7    LC
  Transceiver: 7004404000000000 4,8,16_Gbps M5 sw Short_dist
  Encoding:    6    64B66B 
  Baud Rate:   140  (units 100 megabaud)
  Length 9u:   0    (units km)
  Length 9u:   0    (units 100 meters)
  Length 50u (OM2):  3    (units 10 meters)
  Length 50u (OM3):  10   (units 10 meters)
  Length 62.5u:0    (units 10 meters)
  Length Cu:   0    (units 1 meter)       
  Vendor OUI:  00:05:1e
  Vendor PN:   57-0000088-01   
  Vendor Rev:  A   
  Wavelength:  850  (units nm)
  Options:     003a Loss_of_Sig,Tx_Fault,Tx_Disable
  BR Max:      0   
  BR Min:      0   
  Date Code:   180316  
  DD Type:     0x68
  Enh Options: 0xfa
  Status/Ctrl: 0xb2
  Pwr On Time: 3.52 years (30822 hours)
  E-Wrap Control: 0
  O-Wrap Control: 0
  Alarm flags[0,1] = 0x5, 0x40
  Warn Flags[0,1] = 0x5, 0x40
  Temperature: 32      Centigrade 
  Current:     8.082   mAmps 
  Voltage:     3311.6  mVolts 
  RX Power:    -5.5    dBm (280.4uW) 
  TX Power:    -2.8    dBm (523.1 uW) 
  
  </code></pre>
  <p>I need to fetch the last 2 lines only, that is starting with RX and TX out of it.</p>
  <p>I was trying like</p>
  <pre><code>#$streamOut | Select-String -Pattern &quot;^RX&quot; | select -ExpandProperty line
  $streamOut | Select-String -Pattern &quot;RX&quot; | select -ExpandProperty line
  </code></pre>
  <p>This is by code</p>
  <pre><code>$session = New-SSHSession -ComputerName $SAN_IP -Credential $cred
  $Strem = New-SSHShellStream -SSHSession $Session
  $streamOut=@()
  $SystemView = $Strem.WriteLine(&quot;sfpshow $port_Num&quot;)  
  sleep -Seconds 5      
  $streamOut = @($Strem.read())
  sleep -Seconds 5
  $RXTX_Data = @($streamOut | ? { $_ -match &quot;^RX&quot; -or  $_ -match &quot;^TX&quot;})      
  
  $RXTX_Data
  </code></pre>
  <p>When I use the below solution in above code, it is returning blank. the <strong>$streamOut</strong> is array</p>
  <pre><code>PS C:\Windows\system32&gt; $streamOut.GetType()
  
  IsPublic IsSerial Name                                     BaseType                                                                                                      
  -------- -------- ----                                     --------                                                                                                      
  True     True     Object[]                                 System.Array                                                                                                  
  </code></pre>
  <p>But it is returning the entire output.</p>
  <p>Please let me know on this</p>