The other day I need a year's worth of 'week commencing' dates to complete a work-related task. The thought of collecting them manually never entered my head!
Here's what I did:
$Start = Get-Date 27/06/2016
$i = 1
Add-Content -Value "$($Start.Day)/$($Start.Month)/$($Start.Year)" -Path dates.txt
$Start = $Start.AddDays(7)
Until ($i -eq 52)
- Create a datetime object with the first week commencing date
- Set a counter to 1
- Use a Do Until loop to...
- write the current iteration's week commencing date to a file
- increment the datetime object by 7 days
- increment the count by
- Keep looping until 52 entries have been added to the file