title: Executing Powershell script in c# and wait for the result
body: <p>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?</p>
  <p>This already outputs the result. I just want to wait for the result to finish rather than jumping to the next method prematurely.</p>
  <p>Example/what I'm trying to do</p>
  <pre><code>     Process.Start()
          //Wait for result here
  </code></pre>
  <p>The current method is below:</p>
  <pre><code>public void ExecutePowershellScript()
  {
    var file = @&quot;C:\Path\filename.ps1&quot;;
             
              var start = new ProcessStartInfo()
              {
                  FileName = &quot;powershell.exe&quot;,
                  Arguments = $&quot;-NoProfile -ExecutionPolicy unrestricted -file \&quot;{file}\&quot;&quot;,
                  UseShellExecute = false
              };
              Process.Start(start);
  }
  </code></pre>