PowerShell: Determine The Last Day of a Month (incl. the Day of the Week)

Except for February, it is possible to hard-code the last day of each month since the number of days is fixed. However, you still have to determine the day of the week separately.

Rather than doing this manually, the code snippet below should do the trick:

#determine the last day of the first quarter of the year 2020 including the day of the week (Jan to March)


$date = Get-Date "2020-01-01"
$qtr2 = $date.AddMonths(3)
$qtr2
#Mittwoch, 1. April 2020 00:00:00


$qtr2FirstDay = Get-Date -Month $qtr2.Month -Day 1 -Year $qtr2.year;
$qtr2FirstDay
#Mittwoch, 1. April 2020 23:56:43


$qtr1LastDay = $qtr2FirstDay.AddDays(-1);
$qtr1LastDay
#Dienstag, 31. März 2020 23:56:43