public void UpdateContact(string distinguishedName, MailContactObject mailContact) { ExchangePowershell powershell = null; CPDatabase database = null; try { // Get company distinguished name database = new CPDatabase(); var contact = (from c in database.Contacts where c.DistinguishedName == distinguishedName select c).First(); powershell = new ExchangePowershell(StaticSettings.ExchangeURI, StaticSettings.Username, StaticSettings.DecryptedPassword, StaticSettings.ExchangeUseKerberos, StaticSettings.PrimaryDC); string returnedDN = powershell.UpdateContact(distinguishedName, mailContact.DisplayName, mailContact.Hidden); contact.DistinguishedName = returnedDN; database.SaveChanges(); } catch (Exception ex) { ThrowEvent(Base.Enumerations.AlertID.FAILED, ex.Message); } finally { if (database != null) database.Dispose(); if (powershell != null) powershell.Dispose(); } }