title: Powershell - extract first and third element from string variable
body: <p>I have a variable called $Disk which is populated via a foreach loop that processes the output of a command that returns many lines of output.</p>
  
  <p>For each iteration of the loop the $Disk variable contains data similar to:</p>
  
  <pre><code>Harddisk4  Disk1  SQLDG1  MBR   0     0   Offline     DISKS@SERVER1    P4C0T0L3 - -    F6799A78-9C10-443C-B4E6-22E3B30563C0 60003FFF409638B0B4E622E3B30563C0
  </code></pre>
  
  <p>I need to extract the first and third words from this string; all “words” in the string can be of variable length.</p>
  
  <p>I would like to end up with:</p>
  
  <p><code>$Harddisk</code> equal to: <code>Harddisk4</code></p>
  
  <p><code>$DG</code> equal to: <code>SQLDG1</code></p>
  
  <p>So far I have not found a way to do this. What options does powershell have to accomplish this?</p>