title: Loop over array
body: <p>I need a piece of powershell-code to search and replace a certain string inside a text-file. In my example, I want to replace 23-06-2016' with '24-06-2016'. The script below does this job:</p>
  
  <pre><code>$original_file  = 'file.old'
  $destination_file   = 'file.new'
  
  (Get-Content $original_file) | Foreach-Object {
  $_ -replace '23-06-2016', '24-06-2016' `
  } | Out-File -encoding default $destination_file
  </code></pre>
  
  <p>As the search / replace string change I want to loop over an array of dates which might look like this:</p>
  
  <pre><code>$dates = @("23-06-2016","24-06-2016","27-06-2016")
  </code></pre>
  
  <p>I tried use the </p>
  
  <pre><code>$original_file  = 'file.old'
  $destination_file   = 'file.new'
  
  foreach ($date in $dates) {
    (Get-Content $original_file) | Foreach-Object {
    $_ -replace 'date', 'date++' `
    } | Out-File -encoding default $destination_file
  }
  </code></pre>
  
  <p>In a first step, the date '23-06-2016' should be replaced by '24-06-2016' and in a second step, the date '24-06-2016' should be replaced by '27-06-2016'.</p>
  
  <p>As my script is not working I am seeking for some advice.</p>