public ActionResult SetMailboxAutoResize(FormCollection _POST) { try { CustomMailboxAutoResize mailboxAutoResize = new CustomMailboxAutoResize() { Organization = _POST["organization"], ExcludeFromAutoResize = _POST["exclude"] == "true" ? true : false }; model.MailboxAutoResize = mailboxAutoResize; CommonCAS.Log(string.Format("has run Mail/SetMailboxAutoResize() for organization {0} to set exclude to {1}", mailboxAutoResize.Organization, mailboxAutoResize.ExcludeFromAutoResize)); // execute powershell script and dispose powershell object using (MyPowerShell ps = new MyPowerShell()) { ps.SetMailboxAutoResize(mailboxAutoResize); var result = ps.Invoke(); } CommonCAS.Stats("Mail/SetMailboxAutoResize"); if (mailboxAutoResize.ExcludeFromAutoResize) { model.OKMessage.Add(string.Format("Excluded {0} from mailbox auto resizing", mailboxAutoResize.Organization)); } else { model.OKMessage.Add(string.Format("Enabled mailbox auto resizing for {0}", mailboxAutoResize.Organization)); } return(View("SetMailboxAutoResize", model)); } catch (Exception exc) { CommonCAS.Log("Exception: " + exc.Message); model.ActionFailed = true; model.Message = exc.Message; return(View(model)); } }