Project Description

A simple yet powerful ASP.NET control collection that lets you execute PowerShell scripts within an ASP.NET page.

PowerShell with ASP.NET Page Events

You can have zero or more elements for a particular Page event and execute PowerShell script as a response to the event. Output objects are converted to strings and rendered, or use of the ASP.NET objects you'd expect to be available is acceptable as well.

<PowerShell:Runspace ID="runspace" runat="server">
    <OnInit>
        $Response.Write("OnInit<br />")
    </OnInit>
    <OnLoad>
        $Response.Write("OnLoad<br />")
    </OnLoad>
    <OnLoad Source="~/ExternalPowerShellScript.ps1" />
    <OnRender>
        "OnRender<br />"
    </OnRender>
    <OnUnload>
        $Response.Write("OnUnload<br />")
    </OnUnload>
</PowerShell:Runspace>

PowerShell Data Binding

Creating ASP.NET DataSource containers for binding to ASP.NET controls makes it very easy to render PowerShell object output.

<PowerShell:DataSource ID="ServicesDataSource" runat="server">
  <Script>
    Get-WmiObject Win32_Service
  </Script>
</PowerShell:DataSource>

<asp:Repeater runat="server" DataSourceID="ServicesDataSource">
  <ItemTemplate>
    <div>
      <%# DataBinder.Eval(Container.DataItem, "DisplayName") %> 
        (<%# DataBinder.Eval(Container.DataItem, "Name") %>)
         <%# DataBinder.Eval(Container.DataItem, "State") %>
    </div>
    </ItemTemplate>
</asp:Repeater>

Last edited Jul 20, 2012 at 11:35 PM by adweigert, version 5