title: Removing lines with past dates from a text file
body: <p>I have a text file called HelplineSpecialRoster.txt that looks like this</p>
  
  <pre><code>01/01/2019,6AM,0400012345,Kurt,kurt@outlook.com
  02/01/2019,6AM,0412345676,Bill,bill@outlook.com
  03/01/2019,6AM,0400012345,Sam,Sam@outlook.com
  04/01/2019,6AM,0412345676,Barry,barry@outlook.com
  05/01/2019,6AM,0400012345,Kurt,kurt@outlook.com
  </code></pre>
  
  <p>I'm in Australia so the dates are day/month/year.</p>
  
  <p>I have some code that creates a listbox that displays the lines from the text file, but I want to edit the text file before it is displayed to only show older dates. A helpful person gave me this code and it worked once but now it stopped working for some reason. When I delete the whole text file and recreated it it started working again but only once. </p>
  
  <p>If there is a future shift in the file say </p>
  
  <pre><code>05/02/2019,6AM,0400012345,Kurt,kurt@outlook.com
  </code></pre>
  
  <p>and todays date being 29/01/2019 it works to delete the older shifts. If there is only old shifts in the file as above, it doesn't delete them. When I add a date that is in the future, then it works to delete the older ones and only keep the future one.</p>
  
  <pre><code>$SpecialRosterPath = "C:\Helpline Dialer\HelplineSpecialRoster.txt"
  $CurrentDate2 = (Get-Date).Date  # to have a datetime starting today at 00:00:00
  
  Function DeleteOlderShifts {
      $CurrentAndFutureShifts = Get-Content $SpecialRosterPath | Where-Object {
          $_ -match "^(?&lt;day&gt;\d{2})\/(?&lt;mon&gt;\d{2})\/(?&lt;year&gt;\d{4})" -and
          (Get-Date -Year $Matches.year -Month $Matches.mon -Day $Matches.day) -ge $CurrentDate2
      }
      $CurrentAndFutureShifts
      $CurrentAndFutureShifts | Set-Content $SpecialRosterPath
  }
  
  DeleteOlderShifts;
  </code></pre>
  
  <p>Any ideas?</p>