How to keep a powershell script running 24/7
===

I have a PowerShell script that needs to be restarted when it dies for whatever reason, be it a crash, a self exit or after a system reboot...

How can I, from a bat or another powershell script, see to it that if it is not running, it will be started again...

i.e. how can I find out if it is already running from another script?

I know I can make one powershell script start the active one and simply have it loop a new start as long as it doesnt exit with a specific error... but then THAT scripts need to be seen to :D   So we are back to the original quesiton, how do I keep THAT script running 24/7?

    do 
    {
      $date = Get-Date -format "yyyy-MM-ddTHH:mm:ss"
      "$($date) Repeat : Restarting Worker, LastExitCode $($LastExitCode)." | Out-File D:\IDM\Worker\Worker.LOG -width 180 -append
      powershell -File "D:\IDM\Scripts\Worker.ps1"
      sleep 10
    } 
    while ($LastExitCode -ne $null)