title: how to run powershell script command in asp.net?
body: <p>I want to run powershell script from asp.net page. Here the script</p>
  
  <p>when i run this script i received the below error. 
  "The name 'PowerShell' does not exist in the current". Check this code and provide solution..</p>
  
  <pre><code>using System;
  using System.Collections;
  using System.Configuration;
  using System.Data;
  using System.Linq;
  using System.Web;
  using System.Web.Security;
  using System.Web.UI;
  using System.Web.UI.HtmlControls;
  using System.Web.UI.WebControls;
  using System.Web.UI.WebControls.WebParts;
  using System.Xml.Linq;
  using System.Management.Automation;
  using System.Text;
  using System.Collections.ObjectModel;
  
  
  namespace Poweshellproject
  {
      public partial class _Default : System.Web.UI.Page
      {
          protected void Page_Load(object sender, EventArgs e)
          {
  
          }
  
          protected void ExecuteCode_Click(object sender, EventArgs e)
          {
              // Clean the Result TextBox
              ResultBox.Text = string.Empty;
  
              // Initialize PowerShell engine
              var shell = PowerShell.Create();
  
              // Add the script to the PowerShell object
              shell.Commands.AddScript(PowerShellCodeBox.Text);
  
              // Execute the script
              var results = shell.Invoke();
  
              // display results, with BaseObject converted to string
              // Note : use |out-string for console-like output
              if (results.Count &gt; 0)
              {
                  // We use a string builder ton create our result text
                  var builder = new System.Text.StringBuilder();
  
                  foreach (var psObject in results)
                  {
                      // Convert the Base Object to a string and append it to the string builder.
                      // Add \r\n for line breaks
                      builder.Append(psObject.BaseObject.ToString() + "\r\n");
                  }
  
                  // Encode the string in HTML (prevent security issue with 'dangerous' caracters like &lt; &gt;
                  ResultBox.Text = Server.HtmlEncode(builder.ToString());
              }
  
          }
  
      }
  }
  </code></pre>