title: Odd Powershell Variable Behavior
body: <p>The script below demonstrates the unexpected behavior in powershell which baffles me.  The issue is most likely something I'm doing wrong, but I'm unable to figure it out.  The script looks at specific times of specific days and depending on a set of parameters it takes various actions.  I have a Boolean which alternates on iterations of the included loop.  Or at least it should, therein lies the problem.  Here's an example script which demonstrates how I'm using the variables and produces the odd behavior:</p>
  
  <pre><code>$DisabledRequests = $false
  $Time = Get-Date -UFormat %R
  $Day = Get-Date -UFormat %u
  
  function checktime() {
  
  
  if($Time -ge "07:00" -and $Time -le "19:00" -and $Day -le "5"){
  
      if($DisabledRequests -eq $false){
          Write-Host "Time is $time, Day is $day.  Inside disabledrequests -eq false statement."
          $DisabledRequests = $true #Sets variable to true
          $DisabledRequests -eq $true #Prints true on the console because the statement is true
      }else{
  
  
      }
  
  }else{
  
      Write-Host "Outside limited time parameters."
      if($DisabledRequests -eq $true){
              Write-Host "Changing disabled requests var to false."
              $DisabledRequests = $false
      }
  }
  
  }
  
  
  for($i=0; $i -le 10; $i++){
  checktime
  }
  </code></pre>
  
  <p>The expected behavior is that the script should loop though the conditional (at the present moment the conditional relative to time should result in <code>$true</code>) and then another conditional checking the status of the <code>$DisabledRequests</code> variable.  Because the variable is initially <code>$false</code> the conditional runs correctly on the first iteration.  Part of that conditional's actions is to set the variable <code>$DisabledRequests</code> to <code>$true</code>, which it does.  At least, the part about <code>$DisabledRequests -eq $true</code> prints "True" on the console.</p>
  
  <p>The problem is, if the <code>$DisabledRequests</code> variable is now true, why is the conditional <code>($DisabledRequests -eq $false)</code> still being evaluated as true?</p>
  
  <p>EDIT:</p>
  
  <p>I'd like to also add that I've attempted to clear the variable with <code>Clear-Variable</code> and then recreate it with <code>Set-Variable</code> as true, and that doesn't work as expected either.</p>