Author Posts

July 15, 2015 at 1:07 pm

Hello!

I am new to PowerShell scripting your help will be really appreciated!

I need to exit my .ps1 script IF current date is January 1st

Best Regards

July 15, 2015 at 1:49 pm

Stan,

Something like this:

If ( (Get-Date).DayOfYear -gt 1 )
{
# Your code
}

July 15, 2015 at 2:02 pm

Thank you Tim! Did you mean for January 1st should be

 
-eq 1

July 15, 2015 at 2:08 pm

If #Your code is going to be to exit, then yes, you would use -eq 1. I tend to do it in reverse, so as to avoid exiting in the middle of a script, and to talk about the desired condition in a positive way, rather than filtering out the complementary condition. "If today is after January 1, do something."

July 15, 2015 at 2:10 pm

Got it! Thank you for your help!