I'd like to execute powershell commands in .NET framework, handling output and errors, but the following code failed executing any "complex"command.
Process process = new Process();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.WorkingDirectory = IsRoot(location);
process.StartInfo.Arguments = string.Concat("/C powershell.exe /C ", cmd);
process.Start();
process.WaitForExit();
string output = process.StandardOutput.ReadToEnd();
string error = process.StandardError.ReadToEnd();
process.Close();
return (output, error);