We are excited to announce that the IIS.NET Forums are moving to the new Microsoft Q&A experience. Learn more >

View Complete Thread
  • unable to pass the parameter value from ASP page

    May 22, 2019 03:30 PM|Manusan|LINK

    Hi , I have powershell script below to execute from ASP page . I just want to pass the input from textbox to ps script.

    i just want pass the value for $param1 from ASP page . do i need to try different method in PS script ?

    MY PS script

    param (
    [Parameter( Mandatory=$true)]
    get-service $param1 | Out-File "D:\output.txt"

    aspx page

    <form id="form1" runat="server">
    <asp:TextBox runat="server" ID="tbx" Width="248px"></asp:TextBox>
    <asp:Button ID="cmdbutton" runat="server" Text="RUN BATCH"
    onclick="cmdbutton_Click" />

    aspx.cs page

    protected void cmdbutton_Click(object sender, EventArgs e)
    string CN;
    CN = tbx.Text;
    string sourceFile = Server.MapPath("/test.ps1");
    var pshell = PowerShell.Create();
    var output = pshell.Invoke();