One of my team members required me to get the first day of the month using PowerShell. It is easy to do this. In this tutorial, I will explain how to get the day of the month in PowerShell, like getting the last day of the month, using PowerShell with complete scripts and examples.
PowerShell Get First Day of Month
To get the first day of a given month in PowerShell, we can use the Get-Date cmdlet in combination with some date arithmetic. Here’s a simple method to achieve this:
# Get the first day of the current month
$firstDayOfMonth = Get-Date -Day 1
Write-Output $firstDayOfMonthI executed the above script using VS code. You can see the exact output in the screenshot below:

This script sets the day component to 1, effectively giving you the first day of the current month. If you need the first day of a specific month, you can specify the month and year as well:
# Get the first day of a specific month and year
$year = 2024
$month = 9
$firstDayOfSpecificMonth = Get-Date -Year $year -Month $month -Day 1
Write-Output $firstDayOfSpecificMonthCheck out PowerShell Get Day of Week
PowerShell Get Last Day of Month
Getting the last day of the month in PowerShell is slightly more complex. We can achieve this by moving to the first day of the next month and then subtracting one day.
Here is the complete script.
# Get the last day of the current month
$lastDayOfMonth = (Get-Date -Day 1).AddMonths(1).AddDays(-1)
Write-Output $lastDayOfMonthThis script first moves to the first day of the next month using AddMonths(1) and then subtracts one day using AddDays(-1), giving us the last day of the current month.
I executed the above PowerShell script, and you can see the output in the screenshot below:

If you need the last day of a specific month and year, you can modify the script as follows:
# Get the last day of a specific month and year
$year = 2024
$month = 9
$lastDayOfSpecificMonth = (Get-Date -Year $year -Month $month -Day 1).AddMonths(1).AddDays(-1)
Write-Output $lastDayOfSpecificMonthThis is how to get the last day of the current month in PowerShell.
Read Add Months to Date in PowerShell
PowerShell Get First Day of Current Month
Sometimes, you might need the first day of the current month in PowerShell specifically. The method is similar to what we discussed earlier:
Here is an example.
# Get the first day of the current month
$firstDayOfCurrentMonth = Get-Date -Day 1
Write-Output $firstDayOfCurrentMonthThis script is easy to get the first day of the current month using PowerShell.
Here is the output in the screenshot below:

Conclusion
In this tutorial, I explained how to get the first or last day of any month using PowerShell. Whether you’re working with the current month or a specific month and year, the Get-Date cmdlet combined with date arithmetic methods like AddMonths and AddDays can help you achieve this. I hope this helps.
You may also like:
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.