If you’re working with dates in PowerShell, you might find requirements like determining the last Friday of a given month. In this tutorial, I will explain how to find the last Friday of the month using PowerShell with examples.
To find the last Friday of the month using PowerShell, you can create a custom function called Get-LastFridayOfMonth. This function takes two parameters: the year and the month. It calculates the last day of the given month and iterates backward day by day until it finds a Friday. Here’s a concise example:
function Get-LastFridayOfMonth {
param (
[int]$Year,
[int]$Month
)
$lastDay = [datetime]::new($Year, $Month, [datetime]::DaysInMonth($Year, $Month))
while ($lastDay.DayOfWeek -ne 'Friday') {
$lastDay = $lastDay.AddDays(-1)
}
return $lastDay
}
$lastFriday = Get-LastFridayOfMonth -Year 2024 -Month 9
Write-Output "The last Friday of September 2024 is $lastFriday"Get the Last Friday of the Month Using PowerShell
There are various methods to get the last Friday of a month using PowerShell. Let me explain with examples.
Method 1: Using a Custom Function
The best way to find the last Friday of the month in PowerShell is by creating a custom function. Below is a detailed example of how you can achieve this:
Syntax
function Get-LastFridayOfMonth {
param (
[int]$Year,
[int]$Month
)
$lastDay = [datetime]::new($Year, $Month, [datetime]::DaysInMonth($Year, $Month))
while ($lastDay.DayOfWeek -ne 'Friday') {
$lastDay = $lastDay.AddDays(-1)
}
return $lastDay
}This function takes two parameters: the year and the month. It first calculates the last day of the given month and then iterates backward day by day until it finds a Friday.
Example
Here is an example.
function Get-LastFridayOfMonth {
param (
[int]$Year,
[int]$Month
)
$lastDay = [datetime]::new($Year, $Month, [datetime]::DaysInMonth($Year, $Month))
while ($lastDay.DayOfWeek -ne 'Friday') {
$lastDay = $lastDay.AddDays(-1)
}
return $lastDay
}
$lastFriday = Get-LastFridayOfMonth -Year 2024 -Month 9
Write-Output "The last Friday of September 2024 is $lastFriday"Here is the output you can see in the screenshot below:

Check out Get Day of Month in PowerShell
Method 2: Inline Calculation
You can perform the calculation inline if you prefer not to define a function. Here’s how you can do it:
Syntax
$year = 2024
$month = 9
$lastDay = [datetime]::new($year, $month, [datetime]::DaysInMonth($year, $month))
while ($lastDay.DayOfWeek -ne 'Friday') {
$lastDay = $lastDay.AddDays(-1)
}
$lastFriday = $lastDayThis script follows the same logic as the custom function but is written inline for quick, one-off use.
Example
Now, let me show you a few examples.
$year = 2024
$month = 9
$lastDay = [datetime]::new($year, $month, [datetime]::DaysInMonth($year, $month))
while ($lastDay.DayOfWeek -ne 'Friday') {
$lastDay = $lastDay.AddDays(-1)
}
$lastFriday = $lastDay
Write-Output "The last Friday of September 2024 is $lastFriday"Here is the output you can see in the screenshot below:

Read Get the Last Business Day of the Month Using PowerShell
Method 3: Using Get-Date
You can also use the built-in Get-Date cmdlet to assist in finding the last Friday of the month. This method is a bit more concise and leverages PowerShell’s date manipulation capabilities.
Syntax
$year = 2024
$month = 9
$lastDay = Get-Date -Year $year -Month $month -Day ([datetime]::DaysInMonth($year, $month))
while ($lastDay.DayOfWeek -ne 'Friday') {
$lastDay = $lastDay.AddDays(-1)
}
$lastFriday = $lastDayThis script uses Get-Date to generate the last day of the month and then adjust backward to find the last Friday.
Example
For this, let me show you an example.
$year = 2024
$month = 9
$lastDay = Get-Date -Year $year -Month $month -Day ([datetime]::DaysInMonth($year, $month))
while ($lastDay.DayOfWeek -ne 'Friday') {
$lastDay = $lastDay.AddDays(-1)
}
$lastFriday = $lastDay
Write-Output "The last Friday of September 2024 is $lastFriday"You can see the exact output in the screenshot below:

Conclusion
In this tutorial, I explained how to find the last Friday of the month using PowerShell using different methods. If you still have questions, then leave a comment below.
You may also like:
- PowerShell Get Day of Week
- PowerShell: Get the Last Day of the Previous Month
- Get the First Day of Next Month in PowerShell
Bijay Kumar is an esteemed author and the mind behind PowerShellFAQs.com, where he shares his extensive knowledge and expertise in PowerShell, with a particular focus on SharePoint projects. Recognized for his contributions to the tech community, Bijay has been honored with the prestigious Microsoft MVP award. With over 15 years of experience in the software industry, he has a rich professional background, having worked with industry giants such as HP and TCS. His insights and guidance have made him a respected figure in the world of software development and administration. Read more.