Héllo,
I am trying to see the result of my order from a .PS1 file on a Label in ASP.NET.
Do you have a solution ? I have tried several methods without success.
CSharp Code
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Diagnostics;
using System.Text;
using System.CodeDom.Compiler;
using System.IO;
namespace WebAPPTESTPS1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ExecuteCode_Click(object sender, EventArgs e)
{
var SCRIPT_PATH = @"C:\Users\Admin\source\repos\WebAPPTESTPS1\WebAPPTESTPS1\test.ps1";
Process _Proc = new Process();
_Proc.StartInfo.FileName = "Powershell.exe";
//_Proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
_Proc.StartInfo.Arguments = @"/noexit -executionpolicy bypass -File " + SCRIPT_PATH + " '" +ServerName.Text + "'";
_Proc.Start();
ConfirmationMessage.Text = "The command line " +ServerName.Text + " executed no hidden Window.";
ServerName.Text = string.Empty;
_Proc.BeginOutputReadLine();
_Proc.WaitForExit();
//StreamReader outputReader = _Proc.StandardOutput;
//Label1.Text = outputReader.ReadToEnd();
}
}
}
I start in programming. I would like Label1.Text to return the result of the powershell command to me.
Thank you .