Authoring PowerShell ASP Pages

PowerShell ASP pages are simple text files with the *.ps1x extension that contain markup as well as snippets of regular PowerShell code. Unlike ASP.NET, there is no code behind model for PowerShell ASP pages: in this sense they resemble the classic ASP model.

Here is a very simple PowerShell ASP page:


  <html>
    <body>
      <h1>
        Hello <%= $request['name'] %>! 
    </h1>									
   </body>
  </html>

As you can see, everything is HTML markup except the <%= %> section, which means "evaluate this PowerShell expression and print the result". The expression, in this case, is using the intrinsic ASP.NET Request object to get an input parameter named "name" from the query string (or form-data) of the URL.

You can also create full code blocks that include any other kind of PowerShell expression or flow control construct, and even intermingle that with markup code. For example, here is a simple page that will present the list of running processes on the machine:


  <html>
    <body>
      <table>
      <tr><td>ID</td><td>Name</td></tr>
      <% get-process | %{ %>
        <tr>
          <td><%=$_.Id%></td>
          <td><%=$_.ProcessName%></td>
        </tr>
        <% } %>
      </table>
    </body>
  </html>

Copyright (c) 2022 /n software inc. - All rights reserved.
PowerShell Server 2020 - Version 20.0 [Build 8318]