0

I am writing a function to determine our reboot cycle. It works, but I can't get it to return a value (should be a 1 or a 2). What might I be doing wrong?

function Get-BootCycle {
    $devEarliest  =  8
    $devLatest    = 14
    $prodEarliest = 15
    $prodLatest   = 21

    $today = Get-Date

    switch ($today.DayOfWeek) {
        Wednesday {$val = 1}
        Thursday  {$val = 2}
        Friday    {$val = 3}
        Saturday  {$val = 4}
        Sunday    {$val = 5}
        Monday    {$val = 6}
        Tuesday   {$val = 7}
    }

    $dateVal = "'" + [string]$val + "." + ([string]$today.Hour) + "." +
               $today.AddMinutes(-($today.Minute % 30)).Minute + "'"

    if ($today.Day -ge ($devEarliest + $val) -and $today.Day -le ($devLatest + $val)) {
        $bootCycle = "Development"
        $bootCycleVal = 0
    }
    elseif ($today.Day -ge ($prodEarliest + $val) -and $today.Day -le ($prodLatest + $val)) {
        $bootCycle = "Production"
        $bootCycleVal = 1
    }
    else {
        Break
    }
    return $bootCycleVal
}
4
  • 1
    FWIW you can just cast [int]($today.DayOfWeek) instead of using the swtich Commented Jul 10, 2015 at 23:51
  • I was aware of that, but I number the days based on our (Microsoft's) patch week cycle, so I needed the week to start on Wednesday. Commented Jul 13, 2015 at 14:38
  • Sorry didnt see that at first. Still I would use this: ([int](Get-Date).DayOFWeek + 5) % 7 Commented Jul 13, 2015 at 15:45
  • That's helpful. Thanks! Commented Jul 13, 2015 at 16:00

1 Answer 1

3

It's because neither of your conditions are returning true.

Essentially you're running into..

if(10 >= 11 AND 10 <= 17)... returns false

elseif( 10 >= 18 AND 10 <= 24) returns false

else Break Hitting here and breaking

Sign up to request clarification or add additional context in comments.

1 Comment

Ah, my bad. The function works, but this is not currently a dev or prod week. Thanks for your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.