how to set a timeout when executing Powershell & Powercli commands inside asp.net mvc

Question:

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:-

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 …

Answer:

You will have to roll your own timeout command. Below is code I wrote based on a MSDN Blog entry by Keith Babinec – Executing PowerShell scripts from C#. I wrote the sample in Console Application for demonstration purposes only. I find it easier to see what is happen. You can convert it to Asp.Net application by removing the Console Output and other adjustments.

Here is Program.cs

And here is PowerShellHelper.cs

Source:

how to set a timeout when executing Powershell & Powercli commands inside asp.net mvc by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply