I have a console application and a method that executes a PowerShell script within the console application. So what I'm trying to achieve is running it and then waiting for the result before reading the next method. How would I go about this?
This already outputs the result. I just want to wait for the result to finish rather than jumping to the next method prematurely.
Example/what I'm trying to do
Process.Start()
//Wait for result here
The current method is below:
public void ExecutePowershellScript()
{
var file = @"C:\Path\filename.ps1";
var start = new ProcessStartInfo()
{
FileName = "powershell.exe",
Arguments = $"-NoProfile -ExecutionPolicy unrestricted -file \"{file}\"",
UseShellExecute = false
};
Process.Start(start);
}