I would like to emulate a powershell/powershell-ISE console with a winform. Using Powershell.Create()/Invoke(), I can do pretty much everything to replicate the behaviour, but I'm missing something regarding the change of runspace when entering a remote session. Consider the code below:
PowerShell ps = PowerShell.Create();
ps.AddScript("$i = 1").Invoke();
ps.AddScript("Enter-PSSession -computer localhost").Invoke();
var obj = ps.AddScript("$i").Invoke();
// obj contains 1, whereas I would expect not to find $i
I'm wondering how I could make it transparent for the user that typing enter-pssession would actually change the runspace, just like powershell.exe would do.