title: How can I launch this PowerShell script in a new hidden window
body: <p>I am working on a Reboot Scheduling application to be used on simple remote machines. It has to be user friendly though so I have to have multiple scripts and tasks in the background. my main GUI script needs to launch a <strong>Secondary Script</strong> in a NEW hidden window so that the <strong>Main GUI Script</strong> can close.</p>
  
  <p>the <strong>Secondary Script (Reboot.ps1)</strong> will run until the machine restarts if the user has a scheduled reboot pending. </p>
  
  <p>The code below starts the <strong>Secondary Script</strong> hidden but as a sort of "child job", since this script can run "forever" it wont end thus leaving the <strong>Main GUI script</strong> frozen open until killed in task manager (not very user friendly I know..)</p>
  
  <pre><code>    $program = Powershell.exe -windowstyle hidden -file "C:\Reboot.ps1"
      $scriptblock = $ExecutionContext.InvokeCommand.NewScriptBlock("Invoke-Command {$program}")
      Invoke-Command -NoNewScope -Scriptblock $scriptblock
  </code></pre>
  
  <p>So what I'm asking is if anyone knows how to start the <strong>Secondary Script</strong> in a new PowerShell window, instance, environment, anything that allows the <strong>Main GUI Script</strong> to close. Preferably, less intensive if possible. :) thank you!</p>