public ActionResult GetItemsReport(FormCollection _POST) { try { CustomItemsReport GetItemsReport = new CustomItemsReport() { Organization = _POST["organization"], Mail = _POST["mail"], GetALL = _POST["getall"] == "on" ? true : false }; model.ItemsReport = GetItemsReport; CommonCAS.Log(string.Format("has run Mail/GetItemsReport() for organization {0} and sent the report to {1}", GetItemsReport.Organization, GetItemsReport.Mail)); // execute powershell script and dispose powershell object using (MyPowerShell ps = new MyPowerShell()) { ps.GetItemsReport(GetItemsReport.Organization, GetItemsReport.Mail, GetItemsReport.GetALL); var result = ps.Invoke(); } CommonCAS.Stats("Mail/GetItemsReport"); model.OKMessage.Add(string.Format("'{0}' has been sent the report!...", model.ItemsReport.Mail)); return(View("GetItemsReport", model)); } catch (Exception exc) { CommonCAS.Log("Exception: " + exc.Message); model.ActionFailed = true; model.Message = exc.Message; return(View(model)); } }