I'm currently porting a library from .NET Framework to .NET Core. The Framework version of the library makes use of some runspaces in Powershell, which I'm not very familiar with (leave aside the merits of using Powershell in Core for the sake of the question). The relevant code is as follows
using System.Management.Automation;
using System.Management.Automation.Runspaces;
...
RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create();
using (Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration))
{
runspace.Open();
using (RunspaceInvoke invoker = new RunspaceInvoke(runspace))
{
output = invoker.Invoke("Set-ExecutionPolicy Unrestricted");
PrintOutput(output);
...
I know that in .NET Core, RunspaceConfiguration has been deprecated in favor of using InitialSessionState. But I'm not certain what to do with RunspaceInvoke, which doesn't exist (to my knowledge) in .NET Core. What would one use to invoke a runspace (or perform some suitable workaround) in .NET Core?