I am trying to call\create runspace within a class that derived from PSCmdlet. Since PSCmdlet includes a default session state that contains shared data I want to reuse in the runspace, I am wondering if there is a programmatically way to convert the current sessionState into the runspace's InitialSessionState ?
If there is no such way, I am not really understand why such session state info cannot be shared within different runspace. This looks like running a remote runspace to me. Can anyone explain?
For example,
namespace CustomCmdlet.Test
{
[Cmdlet("Get", "Test1")]
public class GetTest1 : PSCmdlet
{
protected override void ProcessRecord()
{ WriteObject("1"); }
}
[Cmdlet("Get", "Test2")]
public class GetTest2 : PSCmdlet
{
protected override void ProcessRecord()
{
// instead of import the module dll using Runspace
// InitialSessionState.ImportModule(new string[] {"CustomCmdlet.Test.dll"});
// Runspace runspace = RunspaceFactory.CreateRunspace(InitialSessionState)
// is it any way to import the PSCmdlet.SessionState into the InitialSessionState?
}
}
We are using PowerShell 4.0, if this is relevant.