Skip to content

Categories:

PowerShell from ASP.NET and System.Management.Automation – SOLVED!

Wow, this took a long time to figure out, but now I can tell you exactly how to get the System.Management.Automation namespace into yout asp.net web site in order to run PowerShell commands.

1. You need to download the Windows SDK.  Download it from here: http://go.microsoft.com/fwlink/?LinkId=79482&clcid=0x409

2. When installing the above SDK, be sure to follow these instructions: http://msdn.microsoft.com/en-us/library/bb204630(VS.85).aspx

3. Reboot the machine.

4. Open the web.config file in your asp.net website and add the following:

    <compilation debug=”true”>
        <assemblies>
            <add assembly=”System.Management.Automation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″/>
        </assemblies>
    </compilation>

5. On the page that you want to do PowerShell things from, put this at the top:

using System.Management.Automation.Runspaces;
using System.Management.Automation;

6. Follow this article for a demo of how to execute commands:

http://www.leastprivilege.com/HostingPowerShellInASPNET.aspx

 

Posted in Uncategorized.

Tagged with , .


2 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. best registry cleaner says

    Nice post…Thank you for sharing some good things!!

  2. Jakke says

    this has worked form me on 2008 but on 2010 version it no longer works.
    Any idea?