public ActionResult ExpandCPURAM(FormCollection _POST) { try { // Expand CPU and create View. CustomExpandCPURAM ExpandCPURAM = new CustomExpandCPURAM() { TaskID = _POST["ExpandCPURAM.TaskID"], VMID = _POST["vmid"].ToUpper(), DateTime = _POST["datetime"].ToString(), CPU = _POST["ExpandCPURAM.CPU"].ToString(), RAM = _POST["ExpandCPURAM.RAM"].ToString(), Email = _POST["ExpandCPURAM.Email"], DynamicMemoryEnabled = _POST[""] }; var CPU = Convert.ToInt32(ExpandCPURAM.CPU); var RAM = Convert.ToInt32(ExpandCPURAM.RAM); if (CPU > 4) { throw new ArgumentException("For core numbers over 4, please contact Drift.."); } if (RAM > 24) { throw new ArgumentException("For RAM configurations over 24, please contact Drift.."); } if (ExpandCPURAM.TaskID.Length == 0) { throw new ArgumentException("Please enter a task id"); } if (ExpandCPURAM.TaskID.Length < 6 || ExpandCPURAM.TaskID.Length > 6) { throw new ArgumentException("The taskid must be 6 characters long."); } CommonCAS.Log(string.Format("has run Service/ExpandCPURAM() to Expand CPU/RAM on server {0}, at date {1}, with TaskID {2}", ExpandCPURAM.VMID, ExpandCPURAM.DateTime, ExpandCPURAM.TaskID)); // execute powershell script and dispose powershell object using (MyPowerShell ps = new MyPowerShell()) { ps.ExpandCPURAM(ExpandCPURAM.VMID, ExpandCPURAM.DateTime, ExpandCPURAM.CPU, ExpandCPURAM.RAM, ExpandCPURAM.Email, ExpandCPURAM.DynamicMemoryEnabled, ExpandCPURAM.TaskID); var result = ps.Invoke(); } model.OKMessage.Add(string.Format("The VM has been scheduled for expansion on {0}. CPU/RAM will be set to: {1} Cores, and {2} GB RAM.", ExpandCPURAM.DateTime, ExpandCPURAM.CPU, ExpandCPURAM.RAM)); CommonCAS.Stats("Service/ExpandCPURAM"); return(View("ExpandCPURAM", model)); } catch (Exception exc) { CommonCAS.Log("Exception: " + exc.Message); model.ActionFailed = true; model.Message = exc.Message; return(View(model)); } }