Files
Perfect11/Perfect11/Library/PowerShell.cs
2025-10-28 19:02:19 +01:00

27 lines
784 B
C#

using System.Diagnostics;
namespace Perfect11.Library
{
public class PowerShell
{
public string Execute(string command)
{
ProcessStartInfo psi = new ProcessStartInfo
{
FileName = "powershell.exe",
Arguments = $"-NoProfile -ExecutionPolicy Bypass -Command \"{command}\"",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
};
using (Process process = Process.Start(psi))
{
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
return output;
}
}
}
}