public string GetMailContacts(string organization) { try { List <AjaxMailContact> mailContacts = new List <AjaxMailContact>(); using (MyPowerShell ps = new MyPowerShell()) { ps.GetMailContacts(organization); IEnumerable <PSObject> result = ps.Invoke(); foreach (PSObject contact in result) { Dictionary <string, object> properties = CommonCAS.GetPSObjectProperties(contact); mailContacts.Add(new AjaxMailContact() { Name = properties["DisplayName"].ToString(), PrimarySmtpAddress = properties["PrimarySmtpAddress"].ToString() }); } } return(new JavaScriptSerializer().Serialize(mailContacts)); } catch (Exception exc) { return(new JsonException(exc).ToString()); } }