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

unable to pass the parameter value from ASP page  [Answered]RSS

1 reply

Last post May 23, 2019 06:22 AM by Able

  • 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();

  • Re: unable to pass the parameter value from ASP page

    May 23, 2019 06:22 AM|Able|LINK

    Hi Manusan,

    According to your description, in power shell if you want to pass parameters in powershell you should readtext firstly then you could pass your script into powershell script.You could write as below:

    Firstly, we  create a powershell script:

    get-service "$a" |Out-File 'd://ps.txt'

    Then in c# code behind:

    public partial class AA : System.Web.UI.Page
            protected void Page_Load(object sender, EventArgs e)
                PowerShell powerShell = PowerShell.Create();
                    .AddParameter("a", Textbox1.text).Invoke();

    Best Regards


    Please remember to click "Mark as Answer" the responses that resolved your issue.
    If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.