title: Powershell Script Timeout After 130 Seconds
body: <p>I have a powershell script that runs a console .exe application.  The console application runs a web service.  The webservice takes approx 10 mins to complete a task.</p>
  
  <p>In a production environment the powershell script finishes after approx 130 seconds and the web service task is terminated.  This is the core problem!  Everything works just fine in a local environment.</p>
  
  <p>Powershell version 2 is running both locally and in production.</p>
  
  <p>When running the powershell script from the console.  Locally, the powershell script prints the return value of the console app.  In production, nothing is printed to the screen.  It just displays a new command prompt.</p>
  
  <p>The task can be run async from a web page in the production environment just fine.</p>
  
  <p>All application code/config files are the same on both local/production environments.</p>
  
  <p>The only thing that makes sense is the powershell script is timing out and terminating the console app that in turn terminates the web service.</p>
  
  <p>Have researched powershell timeouts and have played with different scripts.  But the fact that it works locally seems to indicate a powershell default setting problem.</p>
  
  <p>This page describes timeout settings:
  <a href="http://www.ehow.com/how_12026004_set-timeout-powershell.html" rel="nofollow">http://www.ehow.com/how_12026004_set-timeout-powershell.html</a></p>
  
  <p>But running: Dir WSMan:\localhost\shell results in a path not found error when run in production.</p>
  
  <p>Powerscript is below but has had all sensitive information removed.  Success email is sent after script is run.</p>
  
  <pre><code># attempt to exe file.  iex is an alias for the invoke-expression cmd
  iex "Reminder.exe"
  
  $smtpServer = ""
  $fromAddress = ""
  $toAddress = ""
  $subject = "SUCCESS"
  $msgBody = ""
  
  # $? lets us know if the previous command was successful or not
  # $LASTEXITCODE gives us the exit code of the last Win32 exe execution
  if (!$? -OR $LASTEXITCODE -gt 0)
  {
  $subject = "FAIL"
  }
  
  $smtpClient = new-object Net.Mail.SmtpClient($smtpServer)
  $smtpClient.Credentials = $senderCreds
  $smtpClient.Send($fromAddress,$toAddress,$subject,$msgBody)
  </code></pre>