title: Running powershell from process acts different then from PowerShell ISE
body: <p>I've got PowerShell script that acts like expected if I run it from PowerShell ISE. </p>
  
  <pre><code>$ol = @()
  $ProcessActive = Get-Process outlook -ErrorAction SilentlyContinue
  if($ProcessActive -eq $null)
  {
  $ol = New-Object -comObject Outlook.Application
  }
  else
  {
  $ol = [Runtime.InteropServices.Marshal]::GetActiveObject("Outlook.Application")
  }
  $file = "c:\testfile.pdf"
  
  $mail = $ol.CreateItem(0)
  $Mail.Recipients.Add("test@test.nl") 
  $mail.Subject = "This is a subject"
  $mail.HTMLBody = "&lt;html&gt;&lt;body&gt;&lt;h3&gt;Hello world&lt;/h3&gt;&lt;/body&gt;&lt;/html&gt;"
  $mail.Attachments.Add($file)
  $inspector = $mail.GetInspector
  $inspector.Display()
  </code></pre>
  
  <p>However ... if I start a process in C# to execute the script it will only work if the Outlook process is not running. </p>
  
  <pre><code>        var filename = "script.ps1";
          var fullname = path + filename;
  
          if (System.IO.File.Exists(fullname))
          {
              ProcessStartInfo startInfo = new ProcessStartInfo();
              startInfo.FileName = @"powershell.exe";
              startInfo.Arguments = string.Format(@"&amp; '{0}'", fullname);
              startInfo.RedirectStandardOutput = true;
              startInfo.RedirectStandardError = true;
              startInfo.UseShellExecute = false;
              startInfo.CreateNoWindow = true;
              Process process = new Process();
              process.StartInfo = startInfo;
              process.Start();
              process.WaitForExit();
              System.IO.File.Delete(fullname);
          }
  </code></pre>
  
  <p>The process eventually ends execution and the file is deleted in both cases (outlook running or not).</p>
  
  <p>What do I need to change in order to let the script execute properly when started from a C# process (even if Outlook is running)? </p>
  
  <p>Thanks in advance.</p>