title: how to set a timeout when executing Powershell & Powercli commands inside asp.net mvc
body: <p>I am working on an asp.net mvc web application, and i have the following code which define a loop over a list of servers and  execute PowerCli commands inside my asp.net mvc for each server:-</p>
  
  <pre><code>//Start Loop
      var shell = PowerShell.Create();
      var shell2 = PowerShell.Create();
      var shell3 = PowerShell.Create();
  
      string PsCmd = "add-pssnapin VMware.VimAutomation.Core; $vCenterServer = '" + vCenterName + "';$vCenterAdmin = '" + vCenterUsername + "' ;$vCenterPassword = '" + vCenterPassword + "';" + System.Environment.NewLine;
  
      PsCmd = PsCmd + "$VIServer = Connect-VIServer -Server $vCenterServer -User $vCenterAdmin -Password $vCenterPassword;" + System.Environment.NewLine;
  
      PsCmd = PsCmd + "Get-VMHost " + System.Environment.NewLine;
  
      string PsCmd2 = "add-pssnapin VMware.VimAutomation.Core; $vCenterServer = '" + vCenterName + "';$vCenterAdmin = '" + vCenterUsername + "' ;$vCenterPassword = '" + vCenterPassword + "';" + System.Environment.NewLine;
  
      PsCmd2 = PsCmd2 + "$VIServer = Connect-VIServer -Server $vCenterServer -User $vCenterAdmin -Password $vCenterPassword;" + System.Environment.NewLine;
  
      PsCmd2 = PsCmd2 + " Get-VMHost " + vCenterName + "| Get-VMHostNetworkAdapter -VMKernel" + System.Environment.NewLine;
  
      shell.Commands.AddScript(PsCmd);
      shell2.Commands.AddScript(PsCmd2);
  
      dynamic results = shell.Invoke(); 
      dynamic results2 = shell2.Invoke();
  // end of loop
  </code></pre>
  
  <p>but i have noted that sometimes the shell commands will hang and the execution never ends,, so can i define a timeout behavior ,, so that after 5 minutes to skip the commands if no results were returned ...    </p>