J
jetoo
Hi there,
i'm trying to run a powershell script from a aspx page.
Here's the code:
//Powershell arguments
String powershell = "C:\\WINDOWS\\system32\
\windowspowershell\\v1.0\\powershell.exe";
String args = " -PSConsoleFile \"C:\\Program Files\
\Microsoft\\Exchange Server\\bin\\exshell.psc1\" -noexit -command \".
\'C:\\Program Files\\Microsoft\\Exchange Server\\bin\
\Exchange.ps1\'\"";
//Process class instance
System.Diagnostics.Process proc = new
System.Diagnostics.Process();
proc.EnableRaisingEvents = false;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
//Process file and arguments
proc.StartInfo.FileName = powershell;
proc.StartInfo.Arguments = args;
// Démarrage du processus.
proc.Start();
//Data
StreamWriter sw = null;
string output = proc.StandardOutput.ReadToEnd();
sw = new StreamWriter("C:\\temp\\log.txt");
sw.WriteLine(output);
Console.WriteLine(output);
//Wait till exit
proc.WaitForExit();
proc.Close();
I can see very well the process running in the task manager, but i
can't have output log, so I don't know what's going on.
I'm running it on a windows server 2003.
Any help will be appreciated. Thanks in advance.
i'm trying to run a powershell script from a aspx page.
Here's the code:
//Powershell arguments
String powershell = "C:\\WINDOWS\\system32\
\windowspowershell\\v1.0\\powershell.exe";
String args = " -PSConsoleFile \"C:\\Program Files\
\Microsoft\\Exchange Server\\bin\\exshell.psc1\" -noexit -command \".
\'C:\\Program Files\\Microsoft\\Exchange Server\\bin\
\Exchange.ps1\'\"";
//Process class instance
System.Diagnostics.Process proc = new
System.Diagnostics.Process();
proc.EnableRaisingEvents = false;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
//Process file and arguments
proc.StartInfo.FileName = powershell;
proc.StartInfo.Arguments = args;
// Démarrage du processus.
proc.Start();
//Data
StreamWriter sw = null;
string output = proc.StandardOutput.ReadToEnd();
sw = new StreamWriter("C:\\temp\\log.txt");
sw.WriteLine(output);
Console.WriteLine(output);
//Wait till exit
proc.WaitForExit();
proc.Close();
I can see very well the process running in the task manager, but i
can't have output log, so I don't know what's going on.
I'm running it on a windows server 2003.
Any help will be appreciated. Thanks in advance.