Issue by running PS scripts from IIS7

R

Romu

Hi all,
On my computer, I run W7 64 bits and IIS7. The PoSH execution policy is set
to Unrestricted and the UNC path of my server is well present in the IE
trusted servers list.

I made a little piece of C# code behind which is:

protected void RunBtn_Click(object sender, EventArgs e)
{
ProcessStartInfo psi = new ProcessStartInfo();
psi.UseShellExecute = false;
psi.WorkingDirectory = @"D:\bricoles\TestsVirtualBox";
psi.FileName = "powershell.exe";
psi.Arguments =
@"D:\bricoles\TestsVirtualBox\tests-VirtualBox.ps1";

object[] prms = new object[] { psi };

Thread t = new Thread(new ParameterizedThreadStart(StartThread));
t.Start(prms);
}

private static void StartThread(object o)
{
ProcessStartInfo psi = (ProcessStartInfo)((object[])o)[0];
Process p = new Process();
p.StartInfo = psi;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardOutput = true;
p.OutputDataReceived += new
DataReceivedEventHandler(OutputDataHandler);
p.ErrorDataReceived += new
DataReceivedEventHandler(ErrorDataHandler);
File.WriteAllText("d:/bricoles/output.txt", "--- start ---");
p.Start();
p.BeginErrorReadLine();
p.BeginOutputReadLine();
p.WaitForExit(1800000);
}

private static void OutputDataHandler(object sendingProcess,
DataReceivedEventArgs outLine)
{
if (!String.IsNullOrEmpty(outLine.Data))
{
File.AppendAllText("d:/bricoles/output.txt",
Environment.NewLine + " OUT " + outLine.Data);
}
}

private static void ErrorDataHandler(object sendingProcess,
DataReceivedEventArgs errLine)
{
if (!String.IsNullOrEmpty(errLine.Data))
{
File.AppendAllText("d:/bricoles/output.txt",
Environment.NewLine + " ERR " + errLine.Data);
}
}

And yes, I'm working to automate VirtualBox from PoSH ;-)

When I click my "Run" button on the web page, the output file content is:

--- start ---
ERR File D:\bricoles\TestsVirtualBox\tests-VirtualBox.ps1 cannot be loaded
because
ERR the execution of scripts is disabled on this system. Please see
"get-help about
ERR _signing" for more details.
ERR At line:1 char:49
ERR + D:\bricoles\TestsVirtualBox\tests-VirtualBox.ps1 <<<<
ERR + CategoryInfo : NotSpecified: (:) [], PSSecurityException
ERR + FullyQualifiedErrorId : RuntimeException
ERR

My PoSH scripts is pretty simple:
"toto" | Out-File -FilePath "d:\bricoles\vbox.txt" -Encoding ASCII


Any idea? Thanks.
 

My Computer

Top