Powershell – Get the first and last day of the previous month

Question:

For example , If I run the script on 11/1/2019 or any other day in November I want the date to be change like below.

Output :

My desired output :

Answer:

Use the .net AddMonths() method on your current date object to go back (or forward in time).

And do the date formatting after you do the date math.

Output:

Source:

Powershell – Get the first and last day of the previous month by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply