public void UpdateOrganizationQuotas(string organizationId, int mailboxesNumber, int contactsNumber, int distributionListsNumber) { // update quotas ExchangeLog.LogStart("UpdateOrganizationQuotas"); ExchangeLog.DebugInfo("organizationId: {0}", organizationId); ExchangeLog.DebugInfo("mailboxesNumber: {0}", mailboxesNumber); ExchangeLog.DebugInfo("contactsNumber: {0}", contactsNumber); ExchangeLog.DebugInfo("distributionListsNumber: {0}", distributionListsNumber); Runspace runSpace = null; try { runSpace = OpenRunspace(); ExchangeLog.LogStart("Set-RecipientEnforcementProvisioningPolicy"); Command cmd = new Command("Set-RecipientEnforcementProvisioningPolicy"); cmd.Parameters.Add("Identity", String.Format("{0}\\{1}", organizationId, RecipientQuotaPolicyIdentity)); cmd.Parameters.Add("MailboxCountQuota", ConvertInt32ToUnlimited(mailboxesNumber)); cmd.Parameters.Add("ContactCountQuota", ConvertInt32ToUnlimited(contactsNumber)); cmd.Parameters.Add("DistributionListCountQuota", ConvertInt32ToUnlimited(distributionListsNumber)); // run command ExecuteShellCommand(runSpace, cmd); ExchangeLog.LogEnd("Set-RecipientEnforcementProvisioningPolicy"); } finally { CloseRunspace(runSpace); } ExchangeLog.LogEnd("UpdateOrganizationQuotas"); }
private static Assembly ResolveExchangeAssembly(object p, ResolveEventArgs args) { //Add path for the Exchange 2010 DLLs if (args.Name.Contains("Microsoft.Exchange")) { string exchangePath = GetExchangePath(); if (string.IsNullOrEmpty(exchangePath)) { return(null); } string path = Path.Combine(exchangePath, args.Name.Split(',')[0] + ".dll"); if (!File.Exists(path)) { return(null); } ExchangeLog.DebugInfo("Resolved assembly: {0}", path); return(Assembly.LoadFrom(path)); } else { return(null); } }
public void UpdateOrganizationServicePlan(string organizationId, string programId, string offerId) { // update service plan ExchangeLog.LogStart("UpdateOrganizationServicePlan"); ExchangeLog.DebugInfo("organizationId: {0}", organizationId); ExchangeLog.DebugInfo("programId: {0}", programId); ExchangeLog.DebugInfo("offerId: {0}", offerId); Runspace runSpace = null; try { runSpace = OpenRunspace(); ExchangeLog.LogStart("Update-ServicePlan"); Command cmd = new Command("Update-ServicePlan"); cmd.Parameters.Add("Identity", organizationId); cmd.Parameters.Add("ProgramID", programId); cmd.Parameters.Add("OfferID", offerId); // run command ExecuteShellCommand(runSpace, cmd); ExchangeLog.LogEnd("Update-ServicePlan"); } finally { CloseRunspace(runSpace); } ExchangeLog.LogEnd("UpdateOrganizationServicePlan"); }
public void DeleteOrganizationDomain(string organizationId, string domain) { // remove accepted domain ExchangeLog.LogStart("DeleteOrganizationDomain"); ExchangeLog.DebugInfo("organizationId: {0}", organizationId); ExchangeLog.DebugInfo("domain: {0}", domain); Runspace runSpace = null; try { runSpace = OpenRunspace(); ExchangeLog.LogStart("Remove-AcceptedDomain"); Command cmd = new Command("Remove-AcceptedDomain"); cmd.Parameters.Add("Identity", String.Format("{0}\\{1}", organizationId, domain)); cmd.Parameters.Add("Confirm", false); // run command ExecuteShellCommand(runSpace, cmd); ExchangeLog.LogEnd("Remove-AcceptedDomain"); } finally { CloseRunspace(runSpace); } // remove domain from catch-alls configuration file RemoveCatchAllOrganizationDomain(organizationId, domain); ExchangeLog.LogEnd("DeleteOrganizationDomain"); }
public void AddOrganizationDomain(string organizationId, string domain) { // add accepted domain ExchangeLog.LogStart("AddOrganizationDomain"); ExchangeLog.DebugInfo("organizationId: {0}", organizationId); ExchangeLog.DebugInfo("domain: {0}", domain); Runspace runSpace = null; try { runSpace = OpenRunspace(); ExchangeLog.LogStart("New-AcceptedDomain"); Command cmd = new Command("New-AcceptedDomain"); cmd.Parameters.Add("Organization", organizationId); cmd.Parameters.Add("Name", domain); cmd.Parameters.Add("DomainName", domain); // run command ExecuteShellCommand(runSpace, cmd); ExchangeLog.LogEnd("New-AcceptedDomain"); } finally { CloseRunspace(runSpace); } // add domain to catch-alls configuration file AddCatchAllOrganizationDomain(organizationId, domain); ExchangeLog.LogEnd("AddOrganizationDomain"); }
public List <ExchangeOrganizationDomain> GetOrganizationDomains(string organizationId) { // get accepted domains ExchangeLog.LogStart("GetOrganizationDomains"); ExchangeLog.DebugInfo("organizationId: {0}", organizationId); Runspace runSpace = null; try { runSpace = OpenRunspace(); // get the list of org domains return(GetOrganizationDomains(runSpace, organizationId)); } finally { CloseRunspace(runSpace); } }
public void DeleteOrganization(string organizationId) { ExchangeLog.LogStart("DeleteOrganization"); ExchangeLog.DebugInfo("organizationId: {0}", organizationId); Runspace runSpace = null; try { runSpace = OpenRunspace(); // delete DeleteOrganizationInternal(runSpace, organizationId); } finally { CloseRunspace(runSpace); } // remove all organization domains from catch-alls configuration file RemoveCatchAllOrganization(organizationId); ExchangeLog.LogEnd("DeleteOrganization"); }
public void CreateOrganization(string organizationId, string programId, string offerId, string domain, string adminName, string adminEmail, string adminPassword) { ExchangeLog.LogStart("CreateOrganization"); ExchangeLog.DebugInfo("organizationId: {0}", organizationId); ExchangeLog.DebugInfo("programId: {0}", programId); ExchangeLog.DebugInfo("offerId: {0}", offerId); ExchangeLog.DebugInfo("domain: {0}", domain); ExchangeLog.DebugInfo("adminEmail: {0}", adminEmail); bool organizationCreated = false; Runspace runSpace = null; try { runSpace = OpenRunspace(); #region Create new organization ExchangeLog.LogStart("New-Organization"); Command cmd = new Command("New-Organization"); cmd.Parameters.Add("Name", organizationId); cmd.Parameters.Add("ProgramId", programId); cmd.Parameters.Add("OfferId", offerId); cmd.Parameters.Add("DomainName", domain); cmd.Parameters.Add("Location", OrganizationDefaultLocation); // run command and get DN of created organization Collection <PSObject> result = ExecuteShellCommand(runSpace, cmd); string organizationDN = GetResultObjectDN(result); ExchangeLog.LogInfo("Organization DN: {0}", organizationDN); ExchangeLog.LogEnd("New-Organization"); organizationCreated = true; #endregion #region Create administrator mailbox ExchangeLog.LogStart("New-Mailbox"); SecureString secureAdminPassword = SecurityUtils.ConvertToSecureString(adminPassword); cmd = new Command("New-Mailbox"); cmd.Parameters.Add("Organization", organizationId); cmd.Parameters.Add("Name", adminName); cmd.Parameters.Add("UserPrincipalName", adminEmail); cmd.Parameters.Add("Password", secureAdminPassword); // run command and get DN of created mailbox result = ExecuteShellCommand(runSpace, cmd); string adminDN = GetResultObjectDN(result); ExchangeLog.LogInfo("Administrator account DN: {0}", adminDN); ExchangeLog.LogEnd("New-Mailbox"); #endregion #region Add admin account to "Organization Management" group ExchangeLog.LogStart("Add-RoleGroupMember"); cmd = new Command("Add-RoleGroupMember"); cmd.Parameters.Add("Identity", GetOrganizationManagementGroupDN(organizationDN)); cmd.Parameters.Add("Member", adminDN); cmd.Parameters.Add("BypassSecurityGroupManagerCheck", true); // run command ExecuteShellCommand(runSpace, cmd); ExchangeLog.LogEnd("Add-RoleGroupMember"); #endregion } catch (Exception ex) { // delete organization if it was created if (organizationCreated) { DeleteOrganizationInternal(runSpace, organizationId); } throw ex; } finally { CloseRunspace(runSpace); } ExchangeLog.LogEnd("CreateOrganization"); }
public ExchangeOrganization GetOrganizationDetails(string organizationId) { // get organization details ExchangeLog.LogStart("GetOrganizationDetails"); ExchangeLog.DebugInfo("organizationId: {0}", organizationId); Runspace runSpace = null; try { runSpace = OpenRunspace(); // create organization details object ExchangeOrganization org = new ExchangeOrganization { Name = organizationId }; #region Get organization details Collection <PSObject> result = GetOrganizationDetailsInternal(runSpace, organizationId); if (result.Count == 0) { ExchangeLog.LogWarning("Organization '{0}' was not found", organizationId); return(null); } PSObject objOrg = result[0]; org.DistinguishedName = (string)GetPSObjectProperty(objOrg, "DistinguishedName"); org.ServicePlan = (string)GetPSObjectProperty(objOrg, "ServicePlan"); org.ProgramId = (string)GetPSObjectProperty(objOrg, "ProgramID"); org.OfferId = (string)GetPSObjectProperty(objOrg, "OfferID"); #endregion #region Get organization quotas ExchangeLog.LogStart("Get-RecipientEnforcementProvisioningPolicy"); Command cmd = new Command("Get-RecipientEnforcementProvisioningPolicy"); cmd.Parameters.Add("Identity", String.Format("{0}\\{1}", organizationId, RecipientQuotaPolicyIdentity)); // run command result = ExecuteShellCommand(runSpace, cmd); if (result.Count == 0) { throw new NullReferenceException(String.Format("Recipient quota policy for organization '{0}' was not found", organizationId)); } PSObject objQuota = result[0]; //ExchangeLog.LogInfo(GetPSObjectProperty(objQuota, "MailboxCountQuota").GetType().ToString()); org.MailboxCountQuota = ConvertUnlimitedToInt32((Unlimited <Int32>)GetPSObjectProperty(objQuota, "MailboxCountQuota")); org.ContactCountQuota = ConvertUnlimitedToInt32((Unlimited <Int32>)GetPSObjectProperty(objQuota, "ContactCountQuota")); org.DistributionListCountQuota = ConvertUnlimitedToInt32((Unlimited <Int32>)GetPSObjectProperty(objQuota, "DistributionListCountQuota")); ExchangeLog.LogEnd("Get-RecipientEnforcementProvisioningPolicy"); #endregion #region Get organization statistics // mailboxes ExchangeLog.LogStart("Get-Mailbox"); cmd = new Command("Get-Mailbox"); cmd.Parameters.Add("Organization", organizationId); org.MailboxCount = ExecuteShellCommand(runSpace, cmd).Count; // remove system "DiscoverySearchMailbox" from statistics //if (org.MailboxCount > 0) // org.MailboxCount -= 1; ExchangeLog.LogEnd("Get-Mailbox"); // contacts ExchangeLog.LogStart("Get-Contact"); cmd = new Command("Get-Contact"); cmd.Parameters.Add("Organization", organizationId); org.ContactCount = ExecuteShellCommand(runSpace, cmd).Count; ExchangeLog.LogEnd("Get-Contact"); // distribution lists ExchangeLog.LogStart("Get-DistributionGroup"); cmd = new Command("Get-DistributionGroup"); cmd.Parameters.Add("Organization", organizationId); org.DistributionListCount = ExecuteShellCommand(runSpace, cmd).Count; ExchangeLog.LogEnd("Get-DistributionGroup"); #endregion #region Get domains org.Domains = GetOrganizationDomains(runSpace, organizationId).ToArray(); #endregion #region Administrator e-mail ExchangeLog.LogStart("Get-RoleGroupMember"); cmd = new Command("Get-RoleGroupMember"); cmd.Parameters.Add("Identity", GetOrganizationManagementGroupDN(org.DistinguishedName)); result = ExecuteShellCommand(runSpace, cmd); if (result.Count > 0) { org.AdministratorName = (string)GetPSObjectProperty(result[0], "Name"); SmtpAddress adminEmail = (SmtpAddress)GetPSObjectProperty(result[0], "PrimarySmtpAddress"); org.AdministratorEmail = (adminEmail != null) ? adminEmail.ToString() : null; } ExchangeLog.LogEnd("Get-RoleGroupMember"); #endregion ExchangeLog.LogEnd("GetOrganizationDetails"); return(org); } finally { CloseRunspace(runSpace); } }