public ActionResult ExpandVHD(FormCollection _POST) { try { // Expand VHD and create View. CustomExpandVHD ExpandVHD = new CustomExpandVHD() { TaskID = _POST["ExpandVHD.TaskID"], VMID = _POST["vmid"].ToUpper(), VHDID = _POST["vhdid"], DateTime = _POST["datetime"].ToString(), GB = _POST["ExpandVHD.GB"], Email = _POST["ExpandVHD.Email"] }; var GB = Convert.ToInt32(ExpandVHD.GB); if (GB > 50) { throw new ArgumentException("For more than 50 GB, please contact Drift.."); } if (ExpandVHD.TaskID.Length == 0) { throw new ArgumentException("Please enter a task id"); } if (ExpandVHD.TaskID.Length < 6 || ExpandVHD.TaskID.Length > 6) { throw new ArgumentException("The taskid must be 6 characters long."); } CommonCAS.Log(string.Format("has run Service/ExpandVHD() to Expand VHD on {0} at date {1}, with TaskID {2}. The VHD has been scheduled for {3} GB more..", ExpandVHD.VMID, ExpandVHD.DateTime, ExpandVHD.TaskID, ExpandVHD.GB)); // execute powershell script and dispose powershell object using (MyPowerShell ps = new MyPowerShell()) { ps.ExpandVHD(ExpandVHD.VMID, ExpandVHD.VHDID, ExpandVHD.DateTime, ExpandVHD.GB, ExpandVHD.Email, ExpandVHD.TaskID); var result = ps.Invoke(); if (result.Count() == 0) { model.OKMessage.Add(string.Format("The VM has been scheduled for expansion on {0}, with {1} GB", ExpandVHD.DateTime, ExpandVHD.GB)); } else { model.OKMessage.Add(string.Format("VM has been expanded with following info:")); foreach (PSObject message in result) { model.OKMessage.Add(message.ToString()); CommonCAS.Log(string.Format("ExpandVHD() extra info: {0}", message.ToString())); } } } CommonCAS.Stats("Service/ExpandVHD"); return(View("ExpandVHD", model)); } catch (Exception exc) { CommonCAS.Log("Exception: " + exc.Message); model.ActionFailed = true; model.Message = exc.Message; return(View(model)); } }