title: Copy files to different location based on file headers
body: <p>I am trying to achieve the same result, but getting some strange behavior I am unable to solve by myself.</p>
  
  <p>It only filters out the first <code>if</code>, then treats the rest as <code>else</code>. Does not matter how many different <code>if...else</code> I put in there, then it still only filters out the first <code>if</code>, then treats others as <code>else</code>.</p>
  
  <p>I have also tried moving the headers around, so the once normally being treated as <code>else</code>, would be the first <code>if</code>, but is still only runs the first <code>if</code>.</p>
  
  <pre><code>[string] $FileDirectory = "C:\temp\Move by header\input";
  [string] $OutputPathHeat = "C:\temp\Move by header\HeatMeter";
  [string] $OutputPathWater = "C:\temp\Move by header\WaterMeter";
  [string] $OutputPathOther = "C:\temp\Move by header\Other";
  
  foreach ($FilePath in Get-ChildItem $FileDirectory | Select-Object -     
  ExpandProperty                 
  FullName)
  {
      [string] $Header = Get-Content $FilePath -First 1
  
      if ($Header -match '#serial-number;device-identification;created;value- 
                     data- 
                     count;act-duration,second(s),inst-value,0,0,0;avg- 
                     duration,second(s),inst-value,0,0,0;energy,Wh,inst- 
                     value,0,0,0;volume,m3,inst-value,0,0,0.*') {
          Move-Item $FilePath $OutputPathHeat
      } elseif ($Header -match '#serial-number;device- 
       identification;created;value-data- 
                         count;fabrication-no,,inst- 
       value,0,0,0;datetime,,inst- 
                         value,0,0,0;volume,m3,inst-value,0,0,0.*') {
          Move-Item $FilePath $OutputPathWater
      } else {
          Move-Item $FilePath $OutputPathOther
      }
  }
  </code></pre>