Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Process vs Instance vs Runspace in PowerShell

the [Powershell]::create() - method creates a new PowerShell-"Instance" either in the "current or a new runspace".

Can someone explain how the terms process, instance, runspace and (maybe thread) relate to each other in this regard. In laymen's terms if possible?

like image 607
Moss Avatar asked Nov 18 '25 04:11

Moss


1 Answers

You can think of [Powershell]::Create() as a new powershell session on the separate thread. This session will have some default runspace created but you can change it to another one. Unlike Start-Process (separate process) and Start-Job (child process), [Powershell]::Create() is running on the same process with your main script and sharing memory space with it. This means that you can exchange actual .net objects between the main and child sessions. If sessions run on separate processes they can only exchange with textual/serialized data.

like image 163
Mike Twc Avatar answered Nov 19 '25 17:11

Mike Twc