Powershell is a powerful administration tool which can be readily incorporated into any ASP.NET web site to allow administration and investigation of the server directly from the web site. This tutorial will show you how to integrate Powershell into ASP.NET and execute powershell cmdlets.
This solution was built on Windows Server 2008 R2, using Visua Studio 2010. The code behind is C#. Therefore this should run on any Vista + based windows computer and may run on Windows XP as well. It is necessary to have the Powershell SDK, link at bottom. A reference to Microsoft.System.Automation is required to access powershell and the appropriate using is also required.
It is never sensible to re-write or create a solution that already exists and has been proven to work. Therefore, using the power of Powershell for administration of a server upon which an ASP.NET website is based is logical - integrating the power of Powershell into the website itself of course would be perfect allowing administration of the server from the administrators front-end on the web site.
Integrating Powershell into ASP.NET is embarrassingly easy and something we should all be doing with any web site that has an administrative portal; or to provide information about the server, resources being used etc to you end-users without having to write new code!
The solution offered here is very basic and shows you how to integrate Powershell into an ASP.NET application and how to execute Powershell Cmdlets.
We have in the image above the basic ASP.NET application template, a blue box which displays the output of the commands being executed and four buttons which execute four different Cmdlets.
Please remember to rate the solution.
If you like my samples then please nominate me for an MVP. http://mvp.microsoft.com/en-us/nominate-an-mvp.aspx. Leave me a message if you nominated me!