public ActionResult Enable(FormCollection _POST) { try { // property is disable but means enable model.EnableUser.Organization = _POST["organization"]; model.EnableUser.UserPrincipalName = _POST["userprincipalname"]; model.EnableUser.Confirm = _POST["confirm"] == "on" ? true : false; if (!model.EnableUser.Confirm) { throw new Exception("You must confirm the action."); } CommonCAS.Log(string.Format("has run User/Enable(Confirmed: {0}) on user {1}", model.EnableUser.Confirm, model.EnableUser.UserPrincipalName)); using (MyPowerShell ps = new MyPowerShell()) { ps.EnableUser(model.EnableUser).Invoke(); var result = ps.Invoke(); if (result.Count() == 0) { model.OKMessage.Add("User successfully enabled."); } else { model.OKMessage.Add("User enabled with following info:"); foreach (PSObject message in result) { model.OKMessage.Add(message.ToString()); } } } CommonCAS.Stats("User/EnableUser"); return(View("Enable", model)); } catch (Exception exc) { CommonCAS.Log("Exception: " + exc.Message); model.ActionFailed = true; model.Message = exc.Message; return(View("Enable", model)); } }