Exit .ps1 script IF current date is January 1st

Welcome Forums General PowerShell Q&A Exit .ps1 script IF current date is January 1st

This topic contains 4 replies, has 2 voices, and was last updated by

 
Participant
3 years, 9 months ago.

  • Author
    Posts
  • #27540

    Participant
    Topics: 3
    Replies: 6
    Points: 0
    Rank: Member

    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

  • #27541

    Participant
    Topics: 9
    Replies: 62
    Points: 6
    Rank: Member

    Stan,

    Something like this:

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

    Participant
    Topics: 3
    Replies: 6
    Points: 0
    Rank: Member

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

     
    -eq 1
    
  • #27543

    Participant
    Topics: 9
    Replies: 62
    Points: 6
    Rank: Member

    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."

  • #27544

    Participant
    Topics: 3
    Replies: 6
    Points: 0
    Rank: Member

    Got it! Thank you for your help!

The topic ‘Exit .ps1 script IF current date is January 1st’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort