Exit script IF current date is December 24th or 25th regardless of future years

Hello!

Exit .ps1 script IF current dates Decemeber 24th or December 25th regardless of future years. (Please, Leap year should be addressed)

PowerShell version 2.0

Your help will be really appreciated!

Best Regards

HI Sg68,
not 100% sure what your looking for. But there are many ways to do achieve this. if your not concerned about the year try the code below

$Date1 = "24/12"
$Date2 ="25/12"

$CurrentDate = (Get-Date -UFormat "%d/%m").ToString()

if(($Date1 -eq $CurrentDate) -or ($Date2 -eq "$CurrentDate")){
    Write-Host "Current Date is $(Get-Date -UFormat "%d/%m/%Y")"
    Exit
}
else{
    Write-Host "Current date is not $($Date1) or $($Date2)"

}

Regards
Shihan

Try this…

If((Get-Date -UFormat ‘%d/%m’) -match ‘24/12|25/12’)
{Write-Warning -Message ‘Current date is 24 or 25 December. Exiting process!’;Exit}
Else{‘Current date is not 24 or 25 December. Process continuing’}

Wow, Simple but smart!!!
Thank you so much for your help! Will definitely try it.
Regards

Get-Date returns an object with lots of information in it.

> Get-Date | fl *

DisplayHint : DateTime
DateTime    : Tuesday, December 26, 2017 11:18:38 AM
Date        : 12/26/2017 12:00:00 AM
Day         : 26
DayOfWeek   : Tuesday
DayOfYear   : 360
Hour        : 11
Kind        : Local
Millisecond : 109
Minute      : 18
Month       : 12
Second      : 38
Ticks       : 636498839181097017
TimeOfDay   : 11:18:38.1097017
Year        : 2017


> $d=Get-Date
> $d.Month
> $d.Day

12
26

Thank you for your reply!