System.Management.Automation PowerShell. .ps1 - - . , , powershell.exe.
. , , PowerShell / . , Set-ExecutionPolicy , script.
, - TextBox, PowerShell , :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Management.Automation;
using System.Text;
namespace PowerShellExecution
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ExecuteCode_Click(object sender, EventArgs e)
{
ResultBox.Text = string.Empty;
var shell = PowerShell.Create();
shell.Commands.AddScript(Input.Text);
var results = shell.Invoke();
if (results.Count > 0)
{
var builder = new StringBuilder();
foreach (var psObject in results)
{
builder.Append(psObject.BaseObject.ToString() + "\r\n");
}
ResultBox.Text = Server.HtmlEncode(builder.ToString());
}
}
}
}
To do this when loading a page, you need to create a function that suits your needs and call it from the "Page_Load" function.
Below is information on how to create a page from start to finish using Visual Studio and do it, http://grokgarble.com/blog/?p=142 .
Please vote and check as appropriate if this is helpful.
Thanks Jeff
source
share