date-stamp switch

I have the date.  I have a number of buckets and what to be in each bucket on the right date.  I need a switch statement to assign the bucket membership depending on the date.  that is – On January 1, i want to transition to the new bucket (that means change a variable to reflect the bucket depending on the date).

Get the date (and specify the format),  But it STILl is a datetime variable.  Create a number of trigger dates on\after which we want to change buckets.  Do the reverse of the above – enter a format and tell powershell that that is a date, create a datetime from that.  In the switch statement, compare the current datetime to the switch values.  If the current datetime is greater than a switch, we have gone past that date, move along.  Unless we use greater than and less than, we have a situation where we assign the variable in the first switch and in the second switch and so on until we are no longer greater than – we just keep teaching until we finish the block.  The final value of the variable is the largest “greater than” that was tested.  Might not be ideal, but it works.

I messed it up by also testing for an exact match on the dates – that means that we do something special on the change-over date.  Send an email to state we are changing buckets.

$today = get-date -format "MM/dd/yyyy" #format probably not needed

come to think of this, the format of the today date is not really relevant except as a visual to remind me how to  

We switch on the date.  If today is greater than a trigger date (we passed into the next semester), we set the semester bucket.  If we are ON the cusp of the trigger, we change the bucket AND send an email notification.  We do this for all the listed semesters.  This runs each time the script runs – each time we reset the $semester semester based on the today date.

AFter we set our semester to the last value (and every day after the first change) we also send an email to incidate we are at the end of our configuration and that new dates need to be set.  I guess i could have done that in code so that we are infinitely configured, but i didn’t want to go out that far.  Maybe i will be gone by then.

switch ($today){
{($today) -ge (get-date 09/1/2013)}{$semester = "13FA"}
{($today) -eq (get-date 09/12/2013)}{$semester = "14JA"; $email=$true}
{($today) -gt (get-date 01/01/2014)}{$semester = "14JA"}
{($today) -eq (get-date 01/25/2015)}{$semester = "15SP"; $email=$true}
{($atoday -gt (get-date 01/25/2015)}{$semester = "15SP";$notify = $true}
default {$semester = "not assigned"}
} # end of switch
If ($email) { write-host "changing semester to $semester"}
If ($notify) { write-host "$semester is the final semester coded into the script at ..."}
This entry was posted in Uncategorized. Bookmark the permalink.