title: How can a powershell script detect when task manager has killed it?
body: <p>I have a <code>powershell</code> script that normal runs as foreground process (i.e. an app, on my desktop in a <code>powerhshell</code> console)</p>
  <p>The script is coded such that when <code>ctrl+c</code> is pressed it will go through an orderly shutdown and close.</p>
  <p>The script is currently being run as a background process (i.e. no console), but I still need to make it go through an orderly shutdown when it closes. I need to be able to do one of two things....</p>
  <ol>
  <li>Modify the script to detect when task manager has killed it and do an orderly shutdown (same as when <code>ctrl+c</code> is used normally), OR</li>
  <li>Send the equivalent of a <code>ctrl+c</code> from task manager.</li>
  </ol>