I am running powershell script from c#.
string scriptPath = \"/script/myscript.ps1\";
Runspace runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
Pi
I know I am late to this, but in your script, you need to add global:
in front of the variable you want to return in the Powershell script, so for example:
$global:test = 4
in Powershell script. In C# after you open the runspace, invoke the policy changer, set up the pipline, you do
var result = runspace.SessionStateProxy.PSVariable.GetValue("test");