title: Combining Multiple String Commands Into One Line
body: <p>I'm using PowerShell and running a tool to extract Lenovo hardware RAID controller info to identify the controller number for use later on in another command line (this is part of a SCCM Server Build Task Sequence).  The tool outputs a lot of data and I'm trying to isolate just what I need from the output.</p>
  
  <p>I've been able to isolate what I need, but I'm thinking there has to be a more efficient way so looking for optimizations.  I'm still learning when it comes to working with strings.</p>
  
  <p>The line output from the tool that I'm looking for looks like this:</p>
  
  <pre><code>0 0   0   252:0    17  DRIVE Onln  N  557.861 GB dsbl N  N   dflt -
  </code></pre>
  
  <p>I'm trying to get the 3 characters to the left of the :0 (the 252 but on other models this could be 65 or some other 2 or 3 digit number)</p>
  
  <p>My existing code is:</p>
  
  <pre><code>$ControllerInfo = cmd /c '&lt;path&gt;\storcli64.exe /c0 show'
  
  $forEach ($line in $ControllerInfo) {
      if ($line -like '*:0 *') {
          $ControllerNum = $line.split(':')[0]  # Get everything left of :
          $ControllerNum = $ControllerNum.Substring($ControllerNum.Length -3)  # Get last 3 chars of string
          $ControllerNum = $ControllerNum.Replace(' ', '')  # Remove blanks
          Write-Host $ControllerNum
          break  #stop looping through output
      }
  }
  </code></pre>
  
  <p>The above works but I'm wondering if there's a way to combine the three lines that start with $ControllerNum = so I can have just have a single $ControllerNum = (commands) line to set the variable instead of doing it in 3 lines.  Basically want to combine the Split, Substring and Replace commands into a single line.</p>
  
  <p>Thanks!</p>