title: Try.. catch.. finally fails during Read-Host
body: <p>When the script is executing the <code>Read-Host</code> cmdlet, closing the window does not activate the <code>finally</code> block. Below is an arbitrary but minimally functional example. I'm using PowerShell 5.0. The Beep() is just to make it obvious the finally block executes.</p>
  <pre><code>try {
      $value= Read-Host -Prompt &quot;Input&quot;
      sleep 5
  } finally {
      [Console]::Beep(880,1000)
  }
  </code></pre>
  <ol>
  <li>If you close the window by clicking the red X during the <code>Read-Host</code>
  the <code>finally</code> block will NOT execute.</li>
  <li>If you close the window by clicking the red X during the <code>sleep</code> the
  <code>finally</code> block WILL execute.</li>
  <li>If you interrupt with Ctrl-C at any point, the <code>finally</code> block WILL execute.</li>
  </ol>
  <p>Is there something fundamental I'm missing about why the <code>finally</code> block is NOT executing when closing the window during a <code>Read-Host</code>?</p>
  <p>The full case involves starting a service on an Amazon Snowball device and needing to stop the service if the script is closed. The full case behavior mirrors the example case above.</p>
  <p>EDIT: Changed variable from $input to $value due to comments saying $input is a reserved variable. Does not change behavior.</p>