# Get last day of Month
$LastWeekDay = (Get-Date $date.Date -day 1).AddMonths(1).AddMilliseconds(-1)
# if day is Sat or Sun subtract days until it is not
while(0,6 -contains $LastWeekDay.DayOfWeek.value__){
$LastWeekDay = $LastWeekDay.AddDays(-1)
}
$LastWeekDay
Returns the last weekday of the month for any given date.
PS C:\> $date = Get-Date '6/1/2019' >> $LastWeekDay = (Get-Date $date.Date -day 1).AddMonths(1).AddMilliseconds(-1) >> while(0,6 -contains $LastWeekDay.DayOfWeek.value__){ >> $LastWeekDay = $LastWeekDay.AddDays(-1) >> } >> $LastWeekDay Friday, June 28, 2019 11:59:59 PM