0

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 .

3
  • See this : stackoverflow.com/questions/34398023/… Commented Jul 1, 2020 at 13:02
  • Do you have an example? Commented Jul 1, 2020 at 13:39
  • Not Working PowerShell psinstance = PowerShell.Create(); psinstance.AddScript(@"C:\Users\Admin\source\repos\WebAPPTESTPS1\WebAPPTESTPS1\test.ps1"); var results = psinstance.Invoke(Label1.Text); Commented Jul 1, 2020 at 13:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.