What are Runspaces in Windows PowerShell 2.0?
Today I listened to a HanselMinutes podcast about PowerShell 2.0. Scott Hanselman interviewed Hal Rottenberg and Kirk Munro at TechEd 2009.
They talked about RunSpaces in PowerShell 2.0. Can somebody please explain the concept behind them and give some (real-world) use-cases or examples?
Thanks!
A Runspace is a specific instance of PowerShell which contains MODIFIABLE collections of commands, providers, variables, functions, and language elements that are available to the command line user (or more generically, to the "host" application).
Generally speaking, Runspaces are a developer topic. If you're on the command-line, you can only modify them by modifying your session, and if you're a typical command-line user, you won't really even be aware of Sessions except when you use them to connect remotely to another computer. However, each session has an associated Runspace (or RunspacePool) that controls what is available to you, and it is possible to create "constrained" runspaces in order to only give users access to certain commands and not others....
In PowerShell 2.0 you use the RunspaceFactory class to create Runspaces or RunspacePool. You can read more about Runspaces on MSDN
A powershell runspace is effectively an isolated instance of the powershell runtime, in my understanding any way.
I have recently had some experiences using PowerShell runspaces inside a web application, to provide some administration features via a web interface. In particular it allowed multiple users to use the application at the same time, without affecting each other.
PowerShell runspace is obsolete term. They use PowerShell session (PSSession) now. I would recommend starting with about_PSSessions help topic.