I have the following c# code:
var runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
var runSpaceInvoker = new RunspaceInvoke(runspace);
runSpaceInvoker.Invoke("Set-ExecutionPolicy Unrestricted");
// create a pipeline and feed it the script text
var pipeline = runspace.CreatePipeline();
var command = new Command(@". .\MyScript.ps1");
command.Parameters.Add("MyParam1", value1);
command.Parameters.Add("MyParam2", value2);
pipeline.Commands.Add(command);
pipeline.Invoke();
runspace.Close();
But I am getting the error Powershell ps1 file “is not recognized as a cmdlet, function, operable program, or script file.”
MyScript.ps1 is copied to the bin folder so it is at the same level as the running program.
I found this Powershell ps1 file "is not recognized as a cmdlet, function, operable program, or script file."
But it did not solve the problem. Any idea what else could cause this error?