none
Web Page to Run PowerShell Scripts RRS feed

  • Question

  • Have any one created web page to run powershell scripts ??

    I have multiple powershell scripts for which i want to create a WebPage so it will be easy for users to run any script as required by them from the webpage.

    Please advice if anyone has done this ? IF Yes, Using which technology - HTML/Angular/JS ????


    Manvendra Bele

    Friday, January 4, 2019 9:52 AM

Answers

All replies

  • Friday, January 4, 2019 10:17 AM
  • It is not possible to run PowerShell from a web page. Use the above suggestion intead.


    \_(ツ)_/

    Friday, January 4, 2019 2:25 PM
  • Another way to add GUI to your PowerShell scripts to add .NET based forms and adding control to perform or run desired Scripts.

    https://blogs.technet.microsoft.com/heyscriptingguy/2011/07/24/create-a-simple-graphical-interface-for-a-powershell-script/


    • Edited by asharma5 Friday, January 4, 2019 4:16 PM changes
    Friday, January 4, 2019 4:15 PM
  • Well.... yes and no. It's true that you can't run PoSh code directly from a webpage. But you can trigger PoSh scripts to run on different systems from a webpage. Trying to run scripts on floating og mobile desktops is not something I'd want to try (to many environmental variables to consider), but on an internal server, with the propper authentication set up; we do that for quite a few things.
    Friday, November 8, 2019 1:17 PM
  • You can't run it directly from any webpage. You need som sort of web app wrapper to kick it off. Also, trying to run scripts on floating systems from a webpage is not something I'd recomend trying, as there are way to many environmental variables to consider. However, on static systems it's fully possible:

    C# wrapper Code:

    private List<PSObject> RunPowershellScript(string relativePath, List<CommandParameter> parameters)
            {
                using (PowerShell PowerShellInstance = PowerShell.Create())
                {
    
                    RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create();
                    Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration);
                    runspace.Open();
                    RunspaceInvoke scriptInvoker = new RunspaceInvoke(runspace);
                    Pipeline pipeline = runspace.CreatePipeline();
                    //Here's how you add a new script with arguments
                    Command cmd = new Command(Server.MapPath(relativePath));
                    
                    foreach (var item in parameters)
                    {
                        cmd.Parameters.Add(item);
                    }
                    
                    pipeline.Commands.Add(cmd);
                    // Execute PowerShell script
                    var res = pipeline.Invoke();
                    var results =res.ToList();
                    return results;
                }
            }

    Also check out PoshServer. Google it.

    • Proposed as answer by Cortesz Friday, November 8, 2019 1:40 PM
    Friday, November 8, 2019 1:40 PM