Hello Johnjohn,
Yes, you can run Powershell from ASP.NET code, for your confort.
For example:
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using Microsoft.PowerShell;
var initialSessionState = InitialSessionState.CreateDefault();
initialSessionState.ExecutionPolicy = ExecutionPolicy.Unrestricted;
using (PowerShell powerShell = PowerShell.Create(initialSessionState))
{
powerShell.AddCommand("whoami");
foreach (var item in powerShell.Invoke())
{
Console.WriteLine(item.BaseObject.ToString());
}
if (powerShell.HadErrors)
{
throw new Exception("powershell script had errors");
}
}
--If the reply is helpful, please Upvote and Accept as answer--