如果你想在html文件或你的网站中运行脚本或bat文件想要运行脚本你可以使用visual studio并添加名为PowerShellExecution的Web应用程序default.aspx
PowerShell Command Harness | |
PowerShell Command | |
Result | |
工具菜单选择库包管理器>>包管理器控制台包管理器控制台执行“Install-Package System.Management.Automation”成功执行该包安装后,您将要添加对Default.aspx.cs文件的引用:
using System.Management.Automation;
在你的Default.aspx.cs中
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)
{
// 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(Input.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 > 0)
{
// We use a string builder ton create our result text
var builder = new 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 < >
ResultBox.Text = Server.HtmlEncode(builder.ToString());
}
}
}
}
“PowerShell命令”窗口Get-EventLog安全性 - 最新10(或您最喜欢的cmdlet用于测试) . 或者把脚本放在那只是改变
//shell.Commands.AddScript(Input.Text);
shell.Commands.AddScript("C:\\Scripts\\PowerShell\\PowerShellScript.ps1")
但对于运行脚本,您应该在PowerShell 32位和64位64位中运行Set-ExecutionPolicy旁路
C:\Windows\System32\WindowsPowerShell\v1.0
32位
C:\Windows\SysWOW64\WindowsPowerShell\v1.0
你应该运行visual studio并在你的iis中发布非常简单,为你可以使用的dns添加功能iis
C:\Windows\System32\drivers\etc
在主机文件中
127.0.0.1 soheil.com
我希望我理解你的需要问候