gnychis
gnychis

Reputation: 7555

How to spawn a powershell script or executable that is independent of current process?

I am currently using Pipeline and PowerShell to spawn a separate executable PowerShell script, with the help of Command. Currently, I am invoking the executable from my original process asynchronously.

What I want to do is be able to allow the script or executable that I spawn to run independently of the current process. That way the script can kill the process that spawned it, without also dying. The behavior that I am experiencing right now is that when the script is run and it kills the process that spawned it, it too dies.

How can I spawn the secondary executable to be entirely independent so the process that spawned it can be killed, yet its execution will continue?

Upvotes: 0

Views: 415

Answers (1)

mjolinor
mjolinor

Reputation: 68341

You can use Disconnect-PSSession to disconnect your main process that spawned the job from the job session.

The job will continue to run, and you can use Connect-PSSession from another PowerShell session later to re-connect to the session and receive the job data.

Remote Disconnected Sessions

Upvotes: 1

Related Questions