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

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

    aspx page

    <form id="form1" runat="server">
    <div>
    <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();
    pshell.AddScript(@"D:\Inetpub\PowershellScript\test.ps1").AddParameter(CN);
    var output = pshell.Invoke();
    }