Exemple #1
0
        protected override void SetMailboxFolderPermissions(Runspace runSpace, ExchangeAccount[] existingAccounts, string folderPath, ExchangeAccount[] accounts)
        {
            ExchangeLog.LogStart("SetMailboxFolderPermissions");

            if (string.IsNullOrEmpty(folderPath))
            {
                throw new ArgumentNullException("folderPath");
            }

            if (accounts == null)
            {
                throw new ArgumentNullException("accounts");
            }

            ExchangeTransaction transaction = StartTransaction();

            try
            {
                SetMailboxFolderPermissions(runSpace, folderPath, existingAccounts, accounts, transaction);
            }
            catch (Exception)
            {
                RollbackTransaction(transaction);
                throw;
            }

            ExchangeLog.LogEnd("SetMailboxFolderPermissions");
        }
Exemple #2
0
        internal override Organization CreateOrganizationAddressBookPolicyInternal(string organizationId, string gal, string addressBook, string roomList, string oab)
        {
            ExchangeLog.LogStart("CreateOrganizationAddressBookPolicyInternal");
            ExchangeLog.LogInfo("  Organization Id: {0}", organizationId);
            ExchangeLog.LogInfo("  GAL: {0}", gal);
            ExchangeLog.LogInfo("  AddressBook: {0}", addressBook);
            ExchangeLog.LogInfo("  RoomList: {0}", roomList);
            ExchangeLog.LogInfo("  OAB: {0}", oab);

            ExchangeTransaction transaction = StartTransaction();

            Organization info       = new Organization();
            string       policyName = GetAddressBookPolicyName(organizationId);

            Runspace runSpace = null;

            try
            {
                runSpace = OpenRunspace();
                Command cmd = new Command("New-AddressBookPolicy");
                cmd.Parameters.Add("Name", policyName);
                cmd.Parameters.Add("AddressLists", addressBook);
                cmd.Parameters.Add("RoomList", roomList);
                cmd.Parameters.Add("GlobalAddressList", gal);
                cmd.Parameters.Add("OfflineAddressBook", oab);

                Collection <PSObject> result = ExecuteShellCommand(runSpace, cmd);
                info.AddressBookPolicy = GetResultObjectDN(result);
            }
            catch (Exception ex)
            {
                ExchangeLog.LogError("CreateOrganizationAddressBookPolicyInternal", ex);
                RollbackTransaction(transaction);
                throw;
            }
            finally
            {
                CloseRunspace(runSpace);
            }
            ExchangeLog.LogEnd("CreateOrganizationAddressBookPolicyInternal");
            return(info);
        }
Exemple #3
0
        private void ResetMailboxFolderPermissions(Runspace runSpace, string folderPath, ExchangeAccount[] accounts, ExchangeTransaction transaction)
        {
            ExchangeLog.LogStart("ResetMailboxFolderPermissions");

            foreach (var account in accounts)
            {
                RemoveMailboxFolderPermission(runSpace, folderPath, account);

                transaction.RemoveMailboxFolderPermissions(folderPath, account);
            }

            ExchangeLog.LogEnd("ResetMailboxFolderPermissions");
        }
Exemple #4
0
        private void AddMailboxFolderPermissions(Runspace runSpace, string folderPath, ExchangeAccount[] accounts, ExchangeTransaction transaction)
        {
            ExchangeLog.LogStart("SetMailboxCalendarPermissions");

            foreach (var account in accounts)
            {
                AddMailboxFolderPermission(runSpace, folderPath, account);

                transaction.AddMailboxFolderPermission(folderPath, account);
            }

            ExchangeLog.LogEnd("SetMailboxCalendarPermissions");
        }
Exemple #5
0
        private void SetMailboxFolderPermissions(Runspace runSpace, string folderPath, ExchangeAccount[] existingAccounts, ExchangeAccount[] newAccounts, ExchangeTransaction transaction)
        {
            ResetMailboxFolderPermissions(runSpace, folderPath, existingAccounts, transaction);

            AddMailboxFolderPermissions(runSpace, folderPath, newAccounts, transaction);
        }
Exemple #6
0
        /// <summary>
        /// Creates organization on Mail Server
        /// </summary>
        /// <param name="organizationId"></param>
        /// <returns></returns>
        internal override Organization ExtendToExchangeOrganizationInternal(string organizationId, string securityGroup, bool IsConsumer)
        {
            ExchangeLog.LogStart("CreateOrganizationInternal");
            ExchangeLog.DebugInfo("  Organization Id: {0}", organizationId);

            ExchangeTransaction transaction = StartTransaction();
            Organization        info        = new Organization();
            Runspace            runSpace    = null;

            try
            {
                runSpace = OpenRunspace();

                string server            = GetServerName();
                string securityGroupPath = AddADPrefix(securityGroup);

                //Create mail enabled organization security group
                EnableMailSecurityDistributionGroup(runSpace, securityGroup, organizationId);
                transaction.RegisterMailEnabledDistributionGroup(securityGroup);
                UpdateSecurityDistributionGroup(runSpace, securityGroup, organizationId, IsConsumer);

                //create GAL
                string galId = CreateGlobalAddressList(runSpace, organizationId);
                transaction.RegisterNewGlobalAddressList(galId);
                ExchangeLog.LogInfo("  Global Address List: {0}", galId);
                UpdateGlobalAddressList(runSpace, galId, securityGroupPath);

                //create AL
                string alId = CreateAddressList(runSpace, organizationId);
                transaction.RegisterNewAddressList(alId);
                ExchangeLog.LogInfo("  Address List: {0}", alId);
                UpdateAddressList(runSpace, alId, securityGroupPath);

                //create RAL
                string ralId = CreateRoomsAddressList(runSpace, organizationId);
                transaction.RegisterNewRoomsAddressList(ralId);
                ExchangeLog.LogInfo("  Rooms Address List: {0}", ralId);
                UpdateAddressList(runSpace, ralId, securityGroupPath);

                //create ActiveSync policy
                string asId = CreateActiveSyncPolicy(runSpace, organizationId);
                transaction.RegisterNewActiveSyncPolicy(asId);
                ExchangeLog.LogInfo("  ActiveSync Policy: {0}", asId);

                info.AddressList       = alId;
                info.GlobalAddressList = galId;
                info.RoomsAddressList  = ralId;
                info.OrganizationId    = organizationId;
            }
            catch (Exception ex)
            {
                ExchangeLog.LogError("CreateOrganizationInternal", ex);
                RollbackTransaction(transaction);
                throw;
            }
            finally
            {
                CloseRunspace(runSpace);
            }
            ExchangeLog.LogEnd("CreateOrganizationInternal");
            return(info);
        }
Exemple #7
0
        internal override string CreateMailEnableUserInternal(string upn, string organizationId, string organizationDistinguishedName,
                                                              ExchangeAccountType accountType,
                                                              string mailboxDatabase, string offlineAddressBook, string addressBookPolicy,
                                                              string accountName, bool enablePOP, bool enableIMAP,
                                                              bool enableOWA, bool enableMAPI, bool enableActiveSync,
                                                              long issueWarningKB, long prohibitSendKB, long prohibitSendReceiveKB, int keepDeletedItemsDays,
                                                              int maxRecipients, int maxSendMessageSizeKB, int maxReceiveMessageSizeKB, bool hideFromAddressBook, bool IsConsumer, bool enabledLitigationHold, long recoverabelItemsSpace, long recoverabelItemsWarning)
        {
            ExchangeLog.LogStart("CreateMailEnableUserInternal");
            ExchangeLog.DebugInfo("Organization Id: {0}", organizationId);

            string ret = null;
            ExchangeTransaction transaction = StartTransaction();
            Runspace            runSpace    = null;

            int    attempts = 0;
            string id       = null;

            try
            {
                runSpace = OpenRunspace();
                Command cmd = null;
                Collection <PSObject> result = null;

                //try to enable mail user for 10 times
                while (true)
                {
                    try
                    {
                        //create mailbox
                        cmd = new Command("Enable-Mailbox");
                        cmd.Parameters.Add("Identity", upn);
                        cmd.Parameters.Add("Alias", accountName);
                        string database = GetDatabase(runSpace, PrimaryDomainController, mailboxDatabase);
                        ExchangeLog.DebugInfo("database: " + database);
                        if (database != string.Empty)
                        {
                            cmd.Parameters.Add("Database", database);
                        }
                        if (accountType == ExchangeAccountType.Equipment)
                        {
                            cmd.Parameters.Add("Equipment");
                        }
                        else if (accountType == ExchangeAccountType.Room)
                        {
                            cmd.Parameters.Add("Room");
                        }
                        else if (accountType == ExchangeAccountType.SharedMailbox)
                        {
                            cmd.Parameters.Add("Shared");
                        }

                        result = ExecuteShellCommand(runSpace, cmd);

                        id = CheckResultObjectDN(result);
                    }
                    catch (Exception ex)
                    {
                        ExchangeLog.LogError(ex);
                    }
                    if (id != null)
                    {
                        break;
                    }

                    if (attempts > 9)
                    {
                        throw new Exception(
                                  string.Format("Could not enable mail user '{0}' ", upn));
                    }

                    attempts++;
                    ExchangeLog.LogWarning("Attempt #{0} to enable mail user failed!", attempts);
                    // wait 5 sec
                    System.Threading.Thread.Sleep(1000);
                }

                transaction.RegisterEnableMailbox(id);

                string windowsEmailAddress = ObjToString(GetPSObjectProperty(result[0], "WindowsEmailAddress"));

                //update mailbox
                cmd = new Command("Set-Mailbox");
                cmd.Parameters.Add("Identity", id);
                cmd.Parameters.Add("OfflineAddressBook", offlineAddressBook);
                cmd.Parameters.Add("EmailAddressPolicyEnabled", false);
                cmd.Parameters.Add("CustomAttribute1", organizationId);
                cmd.Parameters.Add("CustomAttribute3", windowsEmailAddress);
                cmd.Parameters.Add("PrimarySmtpAddress", upn);
                cmd.Parameters.Add("WindowsEmailAddress", upn);

                cmd.Parameters.Add("UseDatabaseQuotaDefaults", new bool?(false));
                cmd.Parameters.Add("UseDatabaseRetentionDefaults", false);
                cmd.Parameters.Add("IssueWarningQuota", ConvertKBToUnlimited(issueWarningKB));
                cmd.Parameters.Add("ProhibitSendQuota", ConvertKBToUnlimited(prohibitSendKB));
                cmd.Parameters.Add("ProhibitSendReceiveQuota", ConvertKBToUnlimited(prohibitSendReceiveKB));
                cmd.Parameters.Add("RetainDeletedItemsFor", ConvertDaysToEnhancedTimeSpan(keepDeletedItemsDays));
                cmd.Parameters.Add("RecipientLimits", ConvertInt32ToUnlimited(maxRecipients));
                cmd.Parameters.Add("MaxSendSize", ConvertKBToUnlimited(maxSendMessageSizeKB));
                cmd.Parameters.Add("MaxReceiveSize", ConvertKBToUnlimited(maxReceiveMessageSizeKB));
                if (IsConsumer)
                {
                    cmd.Parameters.Add("HiddenFromAddressListsEnabled", true);
                }
                else
                {
                    cmd.Parameters.Add("HiddenFromAddressListsEnabled", hideFromAddressBook);
                }
                cmd.Parameters.Add("AddressBookPolicy", addressBookPolicy);

                if (enabledLitigationHold)
                {
                    cmd.Parameters.Add("LitigationHoldEnabled", true);
                    cmd.Parameters.Add("RecoverableItemsQuota", ConvertKBToUnlimited(recoverabelItemsSpace));
                    cmd.Parameters.Add("RecoverableItemsWarningQuota", ConvertKBToUnlimited(recoverabelItemsWarning));
                }

                ExecuteShellCommand(runSpace, cmd);

                //Client Access
                cmd = new Command("Set-CASMailbox");
                cmd.Parameters.Add("Identity", id);
                cmd.Parameters.Add("ActiveSyncEnabled", enableActiveSync);
                if (enableActiveSync)
                {
                    cmd.Parameters.Add("ActiveSyncMailboxPolicy", organizationId);
                }
                cmd.Parameters.Add("OWAEnabled", enableOWA);
                cmd.Parameters.Add("MAPIEnabled", enableMAPI);
                cmd.Parameters.Add("PopEnabled", enablePOP);
                cmd.Parameters.Add("ImapEnabled", enableIMAP);
                ExecuteShellCommand(runSpace, cmd);

                //calendar settings
                if (accountType == ExchangeAccountType.Equipment || accountType == ExchangeAccountType.Room)
                {
                    SetCalendarSettings(runSpace, id);
                }

                //add to the security group
                cmd = new Command("Add-DistributionGroupMember");
                cmd.Parameters.Add("Identity", organizationId);
                cmd.Parameters.Add("Member", id);
                cmd.Parameters.Add("BypassSecurityGroupManagerCheck", true);
                ExecuteShellCommand(runSpace, cmd);

                cmd = new Command("Set-MailboxFolderPermission");
                cmd.Parameters.Add("Identity", id + ":\\calendar");
                cmd.Parameters.Add("AccessRights", "None");
                cmd.Parameters.Add("User", "Default");
                ExecuteShellCommand(runSpace, cmd);

                ret = string.Format("{0}\\{1}", GetNETBIOSDomainName(), accountName);
                ExchangeLog.LogEnd("CreateMailEnableUserInternal");
                return(ret);
            }
            catch (Exception ex)
            {
                ExchangeLog.LogError("CreateMailEnableUserInternal", ex);
                RollbackTransaction(transaction);
                throw;
            }
            finally
            {
                CloseRunspace(runSpace);
            }
        }