title: Using a ForEach loop to reverse csv files
body: <p>What I need to do is to take a number of text files (csv, all in one directory) and create files where the entire output is reversed line by line, but keeping the header at the top instead of ending up at the bottom.</p>
  <p>I am able to take one file (by name) and copy the first line and create a new file with just that line in it.  Then I take the original file minus the first line, read it into an array and reverse it.  I then append that to the file that only has the header.  It works fine, except for the output name, which I'd like to be <code>[file-REV.csv]</code> but so far I've only gotten to <code>[file.csv-REV]</code>...</p>
  <p>So, once I had that working, I thought it was time to have the program find all of the <code>csv</code>'s in the directory and loop through them, creating a reverse file for each.</p>
  <p>This is what I have so far:</p>
  <pre><code>cd c:\users\$([Environment]::UserName)\working
  
  $Path = &quot;c:\users\$([Environment]::UserName)\working\&quot;
  
  ForEach ($file in Get-ChildItem -Filter *.csv) {
      Get-Content $file  -totalcount 1 | Set-Content .\$file-REV.csv
      $flip = (get-content | select -Skip 1)
      [array]::Reverse($flip)
      $flip | add-content &quot;$file-REV.csv&quot;
   }
  </code></pre>
  <p>Here is the message I receive when executing the script:</p>
  <blockquote>
  <p>cmdlet Get-Content at command pipeline position 1</p>
  <p>Supply values for the following parameters:</p>
  <p>Path[0]:</p>
  </blockquote>
  <p>I've tried to put in the entire path <code>Get-Content -Path c:\users\jmurphy\working\</code> and then it complains that it can't find the entire path.</p>