I am writing a short c# program which execute a powershell script test.ps1. The code is the following :
Runspace runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript(scriptText);
pipeline.Commands.Add("Out-String");
Collection<psobject> results = pipeline.Invoke();
runspace.Close();
there is a psexec in the test.ps1 but when I run the c# program I get : "psexec is not recognize as a cmdlet ...", but when I launch my script in powershell it works. Something wrong with the runspace ? (I have tried also psexec.exe and c:\windows\system32\psexec.exe)
When you download PStools you extract some files. Put those files in C:\Windows\System32 AND in C:\Windows\Systemwow64.