Try this Get-DayOfMonth function of the AZSBTools PS module
Install-Module AZSBTools -Force -AllowClobber -Scope CurrentUser -SkipPublisherCheck
First Sunday of the current month:
Get-DayOfMonth -DayofWeek Sunday -First
Sunday, March 1, 2020 12:39:43 PM
First Sunday of the next month:
Get-DayOfMonth -DayofWeek Sunday -Month (Get-Date).AddMonths(1).Month -First
Sunday, April 5, 2020 12:39:09 PM
Last Saturday in October 1911
Get-DayOfMonth -DayofWeek Saturday -Month 10 -Year 1911
Saturday, October 28, 1911 12:40:42 PM
Last Tuesday in July 2165
Get-DayOfMonth -DayofWeek Tuesday -Month 7 -Year 2165
Tuesday, July 30, 2165 12:41:50 PM
Built in help:
help Get-DayOfMonth -Full
NAME
Get-DayOfMonth
SYNOPSIS
Function to get a given day of the week such as Sunday of a given Month/Year like March/2020
SYNTAX
Get-DayOfMonth [[-DayofWeek] <String>] [-First] [[-Month] <Int32>] [[-Year] <Int32>] [<CommonParameters>]
DESCRIPTION
Function to get a given day of the week such as Sunday of a given Month/Year like March/2020
PARAMETERS
-DayofWeek <String>
Optional parameter that defaults to 'Sunday'
Valid options are 'Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'
Required? false
Position? 1
Default value Sunday
Accept pipeline input? false
Accept wildcard characters? false
-First [<SwitchParameter>]
Optional switch parameter. By default it retuns the first day of the month
When set to $true, it returns the last day of month
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
-Month <Int32>
Optional parameter from 1 to 12
Required? false
Position? 2
Default value (Get-Date).Month
Accept pipeline input? false
Accept wildcard characters? false
-Year <Int32>
Optional parameter from 1 to 10,000
Required? false
Position? 3
Default value (Get-Date).Year
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
This cmdlet returns a DateTime object
NOTES
Function by Sam Boutros
v0.1 - 26 March 2020
-------------------------- EXAMPLE 1 --------------------------
PS C:\>Get-DayOfMonth
This will return the last Sunday of the current Month/Year as in:
Sunday, March 29, 2020 12:26:49 PM
-------------------------- EXAMPLE 2 --------------------------
PS C:\>Get-DayOfMonth -DayofWeek Monday
This will return the last Monday of the current Month/Year as in:
Monday, March 30, 2020 12:27:34 PM
-------------------------- EXAMPLE 3 --------------------------
PS C:\>Get-DayOfMonth -DayofWeek Saturday -First
This will return the first Saturday of the current Month/Year as in:
Saturday, March 7, 2020 12:28:25 PM
-------------------------- EXAMPLE 4 --------------------------
PS C:\>Get-DayOfMonth -DayofWeek Friday -Month 3 -Year 1945
This will return the last Friday of March 1945 as in:
Friday, March 30, 1945 12:29:54 PM
RELATED LINKS
https://superwidgets.wordpress.com/category/powershell/