Patrick
Patrick

Reputation: 681

Powershell invoke script in new process and within the same runspace

I got within my application (process) an already configured c# Runspace v3. I want to execute my PowerShell script in a new process, but within the same Runspace. How could I accomplish this? I thought, when I start a PowerShell within an existing runspace, then that Runspace will be inherited to the new PowerShell: Unfortunately, this was not the case...

I have seen following interesting methods, but got no solution how these could help: RunspaceFactory.CreateOutOfProcessRunspace Invoke-Command

PS: I can not change within my app the access from Runspace to a PowerShellProcessInstance and also I can not use PSRemoting

Upvotes: 1

Views: 903

Answers (1)

Mathias R. Jessen
Mathias R. Jessen

Reputation: 174990

What you describe is impossible - a single runspace cannot span multiple processes.

Allow me to demonstrate the relevant hierarchical relationships with this state of the art graphic I whipped up in mspaint:

enter image description here

A runspace is bound to a single .NET AppDomain, and an AppDomain cannot span multiple processes.

Upvotes: 5

Related Questions