public ActionResult GetDeviceReport(FormCollection _POST) { try { model.DeviceReport.Organization = _POST["organization"]; model.DeviceReport.UserPrincipalName = _POST["userprincipalname"]; CommonCAS.Log(string.Format("has run Mail/GetDeviceReport for user {0}", model.DeviceReport.UserPrincipalName)); using (MyPowerShell ps = new MyPowerShell()) { ps.GetDeviceReport(model.DeviceReport); var result = ps.Invoke(); if (result.Count() > 2) { foreach (var item in result) { model.DeviceReport.ReportHtml += item.ToString(); } } else { throw new Exception(model.DeviceReport.UserPrincipalName + " does not have any mobile devices connected."); } } CommonCAS.Stats("Mail/GetDeviceReport"); return(View("GetDeviceReportSuccess", model)); } catch (Exception exc) { CommonCAS.Log("Exception: " + exc.Message); model.ActionFailed = true; model.Message = exc.Message; return(View(model)); } }