title: Powershell Iterate Through Two Directories and Write Contents to CSV
body: <p>I have to write the contents of two directories to a CSV where Directory 1 is Column 1 and Directory 2 is Column 2.</p>
  
  <p>I am fairly new to Powershell so please be gentle.</p>
  
  <p>Here is what I have tried:</p>
  
  <pre><code>$source_loc = "Z:\Dir1"
  $dest_loc = "Y:\Dir2"
  $outfile = "C:\Outfile.csv"
  
  $source = get-ChildItem $source_loc
  $dest = get-ChildItem $dest_loc
  
  Remove-Item $outfile -ErrorAction Ignore
  Add-Content $outfile "Old URL, New URL"
  
  $max = ( $source | Measure-Object ).Count
  
  For ( $i = 0; $i -lt $max; $i++ )
  {
      $cur = $source | Select-Object -Index $i | Select Name
      $old = "http://thisisawebsite.web/oldurl/" + $cur
  
      $cur = $dest | Select-Object -Index $i | Select Name
      $new = "http://thisisawebsite.web/newurl/" + $cur
      $line = $old + ',' + $new
      Add-Content $outfile $line
  } 
  </code></pre>
  
  <p>The problem I am having is that right now the output of Outfile.csv looks like this:</p>
  
  <pre><code>http://thisisawebsite.web/oldurl/@{Name=File1.ext},http://thisisawebsite.web/newurl/@{Name=File1.ext}
  http://thisisawebsite.web/oldurl/@{Name=File2.ext},http://thisisawebsite.web/newurl/@{Name=File2.ext}
  </code></pre>
  
  <p>When I want it to look like this:</p>
  
  <pre><code>http://thisisawebsite.web/oldurl/File1.ext,http://thisisawebsite.web/newurl/File1.ext
  http://thisisawebsite.web/oldurl/File2.ext,http://thisisawebsite.web/newurl/File2.ext
  </code></pre>
  
  <p>I tried converting to arrays and indexing into it but it seems to do the same thing.  Do I need to do a substr on the $cur variable and ignore the first 7 characters and then ignore the last one?  I know my code is rubbish so please try your best not to insult me.</p>
  
  <p>Thanks!  ^.^</p>