Windows Server 2012 Countdown with #PowerShell

Share on:

We have 900 days until Windows Server 2012 (and 2012R2) goes End of Life. Here’s how you can use PowerShell to report back the number of days till a deadline.

Details on the Windows Server 2012 Lifecycle can be found here: docs.microsoft.com

To work out how many days until a certain date we can define two variables. The first should be the date in the future, in this case October 10th 2023 for the end of extended support for Windows Server 2012.

1$EOLDate=get-date -Year 2023 -Month 10 -Day 10 -Hour 0 -Minute 0 -Second 1

Secondly we can get a variable that gives us todays date, and as above we’re only interested in the day/month/year and not the time of day.

1$Now= get-date -Hour 0 -Minute 0 -Second 0

With these two DateTime variables we can calculate the difference by subtracting today from the day in the future:

1$EOLDate - $Now

We can neaten this up and just show the number of days like this:

1($EOLDate - $Now).Days

Bringing that all together we get the following snippet of code.

1#PowerShell- How many days till the end of extended support for Windows Server 2012 and 2012R2
2#https://docs.microsoft.com/en-us/lifecycle/products/windows-server-2012-r2
3
4# Set a date variable for the end of Windows Server 2012 Support
5$EOLDate=get-date -Year 2023 -Month 10 -Day 10 -Hour 0 -Minute 0 -Second 1
6# Set a date variable for today
7$Now= get-date -Hour 0 -Minute 0 -Second 0
8# Display a message with the difference between today's date and the End of Support date.
9"There are "+ ($EOLDate - $Now).Days + " days left till the end of extended support for Windows Server 2012"