title: Using same variable names and overwriting in scriptblock
body: <p>I have a script that imports CSV files, formats them (remove certain columns and rows, adds new columns etc) and then exports them back to disk. The processing is such a way that I had to do two import-csv/export-csv on the same files. Here is a code snippet :</p>
  
  <pre><code># Formating 1:
  $files = Get-ChildItem -Path $fileSource -Filter *.csv
  foreach ($file in $files) {
      # do my formating tasks 1...
      Export-Csv $file.FullName -Force -NoTypeInformation
  }
  
  # Formating 2:
  $files = Get-ChildItem -Path $fileSource -Filter *.csv
  foreach ($file in  $files) {
      # do my formating tasks 2
      Export-Csv $file.FullName -Force -NoTypeInformation
  }
  </code></pre>
  
  <p><strong>Question</strong></p>
  
  <p>Is it "OK" to use the same variable names (i.e. <code>$files</code>/<code>$file</code>) in the same script block and overwrite the values as in my case above?</p>