powershell を ASP.net Web ページと統合する方法。いつでも asp.net ページ ボタンをクリックします。リモート Exchange サーバーの PowerShell が実行され、結果が返されます。また、その結果をasp.netページに送り返して、Webページに表示してユーザーに表示する必要があります。これについて助けてください。
ありがとうスワプニル・ガングラード
powershell を ASP.net Web ページと統合する方法。いつでも asp.net ページ ボタンをクリックします。リモート Exchange サーバーの PowerShell が実行され、結果が返されます。また、その結果をasp.netページに送り返して、Webページに表示してユーザーに表示する必要があります。これについて助けてください。
ありがとうスワプニル・ガングラード
C# からの powershell の実行に関するコード プロジェクトの記事を参照してください。サンプルコードは次のとおりです。
private string RunScript(string scriptText)
{
// create Powershell runspace
Runspace runspace = RunspaceFactory.CreateRunspace();
// open it
runspace.Open();
// create a pipeline and feed it the script text
Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript(scriptText);
// add an extra command to transform the script
// output objects into nicely formatted strings
// remove this line to get the actual objects
// that the script returns. For example, the script
// "Get-Process" returns a collection
// of System.Diagnostics.Process instances.
pipeline.Commands.Add("Out-String");
// execute the script
Collection<psobject /> results = pipeline.Invoke();
// close the runspace
runspace.Close();
// convert the script result into a single string
StringBuilder stringBuilder = new StringBuilder();
foreach (PSObject obj in results)
{
stringBuilder.AppendLine(obj.ToString());
}
return stringBuilder.ToString();
}
ただし、この PowerShell を間違ったユーザーとして実行できるため、なりすましには注意してください。