Added reference: PowerShellStandard.Library
Repro inside a default .net-core
project:
// ...
using System.Management.Automation;
using System.Collections.ObjectModel;
// ...
public static void Main(string[] args)
{
Collection<PSObject> output;
using (PowerShell ps = PowerShell.Create())
{
ps.AddScript("$test = Get-Date; $test");
output = ps.Invoke();
}
// ...
I've tried it with or without the using
block, but I end up with the same result: the Create
method is not creating a PowerShell
object, but it's also not throwing an exception.
Is this a common issue with the PowerShell
.net-standard
library? Is there a workaround or another way to solve my problem?
Additional info, this is also happening with the RunspaceFactory
class CreateRunspace
method as I was exploring a workaround with managing runspaces myself.