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 Secondary Script in a NEW hidden window so that the Main GUI Script can close.
the Secondary Script (Reboot.ps1) will run until the machine restarts if the user has a scheduled reboot pending.
The code below starts the Secondary Script hidden but as a sort of "child job", since this script can run "forever" it wont end thus leaving the Main GUI script frozen open until killed in task manager (not very user friendly I know..)
$program = Powershell.exe -windowstyle hidden -file "C:\Reboot.ps1"
$scriptblock = $ExecutionContext.InvokeCommand.NewScriptBlock("Invoke-Command {$program}")
Invoke-Command -NoNewScope -Scriptblock $scriptblock
So what I'm asking is if anyone knows how to start the Secondary Script in a new PowerShell window, instance, environment, anything that allows the Main GUI Script to close. Preferably, less intensive if possible. :) thank you!