I am trying to run this C# code:
Runspace rs = RunspaceFactory.CreateRunspace();
rs.Open();
PowerShell ps = PowerShell.Create();
ps.Runspace = rs;
ps.AddScript("Write-Output Hello | Out-File -FilePath myfile.txt");
ps.Invoke();
myfile.txt should contain Hello but the file does not exist. How can i redirect powershell commands standard output (and errors) ?
Thanks
*** EDIT ***
I have understood the problem: The Invoke command is not a blocking-command. So when Invoke() has finished, my file.txt does not exist yet.
Is there a way to wait for powershelgl script ending ? Thanks
Invokeblocks the thread already.