示例#1
0
        internal override string CreateMailboxDatabase(Runspace runSpace, string name, string storageGroup)
        {
            ExchangeLog.LogStart("CreateMailboxDatabase");
            string id;

            if (name != "*")
            {
                Command cmd = new Command("Get-MailboxDatabase");
                cmd.Parameters.Add("Identity", name);
                Collection <PSObject> result = ExecuteShellCommand(runSpace, cmd);
                if (result != null && result.Count > 0)
                {
                    id = GetResultObjectIdentity(result);
                }
                else
                {
                    throw new Exception(string.Format("Mailbox database {0} not found", name));
                }
            }
            else
            {
                id = "*";
            }
            ExchangeLog.LogEnd("CreateMailboxDatabase");
            return(id);
        }
示例#2
0
        internal override string CreateJournalRuleInternal(string journalEmail, string scope, string recipientEmail, bool enabled)
        {
            ExchangeLog.LogStart("CreateJournalRule");
            ExchangeLog.DebugInfo("journalEmail: {0}", journalEmail);

            Runspace runSpace = null;

            try
            {
                runSpace = OpenRunspace();
                Command cmd = new Command("New-JournalRule");
                cmd.Parameters.Add("Name", GetJournalRuleName(journalEmail));
                cmd.Parameters.Add("JournalEmailAddress", journalEmail);
                cmd.Parameters.Add("Scope", scope);
                cmd.Parameters.Add("Recipient", recipientEmail);
                cmd.Parameters.Add("Enabled", enabled);
                Collection <PSObject> result = ExecuteShellCommand(runSpace, cmd);
                ExchangeLog.LogEnd("CreateJournalRule");
                if (result.Count == 0)
                {
                    return(null);
                }
                return(ObjToString(GetPSObjectProperty(result[0], "Name")));
            }
            catch (Exception ex)
            {
                ExchangeLog.LogError("CreateJournalRule", ex);
                throw;
            }
            finally
            {
                CloseRunspace(runSpace);
            }
        }
示例#3
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");
        }
示例#4
0
        internal override void SetMailboxAutoReplySettingsInternal(string accountName, ExchangeMailboxAutoReplySettings settings)
        {
            ExchangeLog.LogStart("SetMailboxAutoReplySettingsInternal");
            ExchangeLog.DebugInfo("Account: {0}", accountName);

            Runspace runSpace = null;

            try
            {
                runSpace = OpenRunspace();
                Command cmd = new Command("Set-MailboxAutoReplyConfiguration");
                cmd.Parameters.Add("Identity", accountName);
                cmd.Parameters.Add("AutoReplyState", settings.AutoReplyState);
                cmd.Parameters.Add("ExternalAudience", settings.ExternalAudience);
                cmd.Parameters.Add("InternalMessage", settings.InternalMessage);
                cmd.Parameters.Add("ExternalMessage", settings.ExternalMessage);
                cmd.Parameters.Add("StartTime", settings.StartTime);
                cmd.Parameters.Add("EndTime", settings.EndTime);
                ExecuteShellCommand(runSpace, cmd);
            }
            finally
            {
                CloseRunspace(runSpace);
            }
            ExchangeLog.LogEnd("SetMailboxAutoReplySettingsInternal");
        }
示例#5
0
        internal override ExchangeMailboxAutoReplySettings GetMailboxAutoReplySettingsInternal(string accountName)
        {
            ExchangeLog.LogStart("GetMailboxAutoReplySettingsInternal");
            ExchangeLog.DebugInfo("Account: {0}", accountName);

            ExchangeMailboxAutoReplySettings ret = new ExchangeMailboxAutoReplySettings();
            Runspace runSpace = null;

            try
            {
                runSpace = OpenRunspace();
                Command cmd = new Command("Get-MailboxAutoReplyConfiguration");
                cmd.Parameters.Add("Identity", accountName);
                Collection <PSObject> result = ExecuteShellCommand(runSpace, cmd);
                PSObject ar = result[0];
                ret.AutoReplyState   = (OofState)GetPSObjectProperty(ar, "AutoReplyState");
                ret.ExternalAudience = (ExternalAudience)GetPSObjectProperty(ar, "ExternalAudience");
                ret.ExternalMessage  = (string)GetPSObjectProperty(ar, "ExternalMessage");
                ret.InternalMessage  = (string)GetPSObjectProperty(ar, "InternalMessage");
                ret.StartTime        = (DateTime)GetPSObjectProperty(ar, "StartTime");
                ret.EndTime          = (DateTime)GetPSObjectProperty(ar, "EndTime");
            }
            finally
            {
                CloseRunspace(runSpace);
            }
            ExchangeLog.LogEnd("GetMailboxAutoReplySettingsInternal");
            return(ret);
        }
示例#6
0
        internal override void RemoveJournalRuleInternal(string journalEmail)
        {
            ExchangeLog.LogStart("RemoveJournalRule");
            ExchangeLog.DebugInfo("journalEmail: {0}", journalEmail);

            Runspace runSpace = null;

            try
            {
                runSpace = OpenRunspace();
                Command cmd = new Command("Remove-JournalRule");
                cmd.Parameters.Add("Identity", GetJournalRuleName(journalEmail));
                ExecuteShellCommand(runSpace, cmd);
                ExchangeLog.LogEnd("RemoveJournalRule");
            }
            catch (Exception ex)
            {
                ExchangeLog.LogError("RemoveJournalRule", ex);
                throw;
            }
            finally
            {
                CloseRunspace(runSpace);
            }
        }
示例#7
0
        internal static Assembly ResolveExchangeAssembly(object p, ResolveEventArgs args)
        {
            //Add path for the Exchange 2007 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);
            }
        }
示例#8
0
        internal override void SetMailboxAdvancedSettingsInternal(string organizationId, 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 enabledLitigationHold, long recoverabelItemsSpace, long recoverabelItemsWarning,
                                                                  string litigationHoldUrl, string litigationHoldMsg)
        {
            ExchangeLog.LogStart("SetMailboxAdvancedSettingsInternal");
            ExchangeLog.DebugInfo("Account: {0}", accountName);

            Runspace runSpace = null;

            try
            {
                runSpace = OpenRunspace();


                Command cmd = new Command("Set-Mailbox");
                cmd.Parameters.Add("Identity", accountName);
                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));

                cmd.Parameters.Add("LitigationHoldEnabled", enabledLitigationHold);
                cmd.Parameters.Add("RecoverableItemsQuota", ConvertKBToUnlimited(recoverabelItemsSpace));

                cmd.Parameters.Add("RetentionUrl", litigationHoldUrl);
                cmd.Parameters.Add("RetentionComment", litigationHoldMsg);

                if (recoverabelItemsSpace != -1)
                {
                    cmd.Parameters.Add("RecoverableItemsWarningQuota", ConvertKBToUnlimited(recoverabelItemsWarning));
                }

                ExecuteShellCommand(runSpace, cmd);

                //Client Access
                cmd = new Command("Set-CASMailbox");
                cmd.Parameters.Add("Identity", accountName);
                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);
            }
            finally
            {
                CloseRunspace(runSpace);
            }
            ExchangeLog.LogEnd("SetMailboxAdvancedSettingsInternal");
        }
示例#9
0
        internal override void DeleteMailboxInternal(string accountName)
        {
            ExchangeLog.LogStart("DeleteMailboxInternal");
            ExchangeLog.DebugInfo("Account Name: {0}", accountName);

            Runspace runSpace = null;

            try
            {
                runSpace = OpenRunspace();

                Command cmd = new Command("Get-Mailbox");
                cmd.Parameters.Add("Identity", accountName);
                Collection <PSObject> result = ExecuteShellCommand(runSpace, cmd);

                if (result != null && result.Count > 0)
                {
                    string upn = ObjToString(GetPSObjectProperty(result[0], "UserPrincipalName"));
                    string addressbookPolicy = ObjToString(GetPSObjectProperty(result[0], "AddressBookPolicy"));

                    RemoveDevicesInternal(runSpace, accountName);

                    RemoveMailbox(runSpace, accountName);

                    if (addressbookPolicy == (upn + " AP"))
                    {
                        try
                        {
                            DeleteAddressBookPolicy(runSpace, upn + " AP");
                        }
                        catch (Exception)
                        {
                        }

                        try
                        {
                            DeleteGlobalAddressList(runSpace, upn + " GAL");
                        }
                        catch (Exception)
                        {
                        }

                        try
                        {
                            DeleteAddressList(runSpace, upn + " AL");
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
            }
            finally
            {
                CloseRunspace(runSpace);
            }
            ExchangeLog.LogEnd("DeleteMailboxInternal");
        }
示例#10
0
        internal override void SetCalendarSettings(Runspace runspace, string id)
        {
            ExchangeLog.LogStart("SetCalendarSettings");
            Command cmd = new Command("Set-CalendarProcessing");

            cmd.Parameters.Add("Identity", id);
            cmd.Parameters.Add("AutomateProcessing", CalendarProcessingFlags.AutoAccept);
            ExecuteShellCommand(runspace, cmd);
            ExchangeLog.LogEnd("SetCalendarSettings");
        }
示例#11
0
        internal override void SetDistributionListSendOnBehalfAccounts(Runspace runspace, string accountName, string[] sendOnBehalfAccounts)
        {
            ExchangeLog.LogStart("SetDistributionListSendOnBehalfAccounts");
            Command cmd = new Command("Set-DistributionGroup");

            cmd.Parameters.Add("Identity", accountName);
            cmd.Parameters.Add("GrantSendOnBehalfTo", SetSendOnBehalfAccounts(runspace, sendOnBehalfAccounts));
            cmd.Parameters.Add("BypassSecurityGroupManagerCheck");
            ExecuteShellCommand(runspace, cmd);
            ExchangeLog.LogEnd("SetDistributionListSendOnBehalfAccounts");
        }
示例#12
0
        protected override ExchangeAccount[] GetMailboxContactAccounts(Runspace runSpace, string organizationId, string accountName)
        {
            ExchangeLog.LogStart("GetMailboxContactAccounts");

            string cn = GetMailboxCommonName(runSpace, accountName);

            ExchangeAccount[] ret = GetContactAccounts(runSpace, organizationId, cn);

            ExchangeLog.LogEnd("GetMailboxContactAccounts");
            return(ret);
        }
示例#13
0
        internal override void RemoveDistributionGroup(Runspace runSpace, string id)
        {
            ExchangeLog.LogStart("RemoveDistributionGroup");
            Command cmd = new Command("Remove-DistributionGroup");

            cmd.Parameters.Add("Identity", id);
            cmd.Parameters.Add("Confirm", false);
            cmd.Parameters.Add("BypassSecurityGroupManagerCheck");
            ExecuteShellCommand(runSpace, cmd);
            ExchangeLog.LogEnd("RemoveDistributionGroup");
        }
示例#14
0
        private ExchangeAccount[] GetContactAccounts(Runspace runSpace, string organizationId, string accountId)
        {
            ExchangeLog.LogStart("GetContactAccounts");

            var folderPath = GetMailboxFolderPath(accountId, ExchangeFolders.Contacts);

            var accounts = GetMailboxFolderPermissions(runSpace, organizationId, folderPath);

            ExchangeLog.LogEnd("GetContactAccounts");
            return(accounts.ToArray());
        }
示例#15
0
        internal override void DeleteAddressBookPolicy(Runspace runSpace, string id)
        {
            ExchangeLog.LogStart("DeleteAddressBookPolicy");
            //if (id != "IsConsumer")
            //{
            Command cmd = new Command("Remove-AddressBookPolicy");

            cmd.Parameters.Add("Identity", id);
            cmd.Parameters.Add("Confirm", false);
            ExecuteShellCommand(runSpace, cmd);
            //}
            ExchangeLog.LogEnd("DeleteAddressBookPolicy");
        }
示例#16
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");
        }
示例#17
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");
        }
示例#18
0
        internal override void AdjustADSecurity(string objPath, string securityGroupPath, bool isAddressBook)
        {
            ExchangeLog.LogStart("AdjustADSecurity");
            ExchangeLog.DebugInfo("  Active Direcory object: {0}", objPath);
            ExchangeLog.DebugInfo("  Security Group: {0}", securityGroupPath);

            if (isAddressBook)
            {
                ExchangeLog.DebugInfo("  Updating Security");
                //"Download Address Book" security permission for offline address book
                Guid openAddressBookGuid = new Guid("{bd919c7c-2d79-4950-bc9c-e16fd99285e8}");

                DirectoryEntry groupEntry = GetADObject(securityGroupPath);
                byte[]         byteSid    = (byte[])GetADObjectProperty(groupEntry, "objectSid");

                DirectoryEntry          objEntry = GetADObject(objPath);
                ActiveDirectorySecurity security = objEntry.ObjectSecurity;

                // Create a SecurityIdentifier object for security group.
                SecurityIdentifier groupSid = new SecurityIdentifier(byteSid, 0);

                // Create an access rule to allow users in Security Group to open address book.
                ActiveDirectoryAccessRule allowOpenAddressBook =
                    new ActiveDirectoryAccessRule(
                        groupSid,
                        ActiveDirectoryRights.ExtendedRight,
                        AccessControlType.Allow,
                        openAddressBookGuid);

                // Create an access rule to allow users in Security Group to read object.
                ActiveDirectoryAccessRule allowRead =
                    new ActiveDirectoryAccessRule(
                        groupSid,
                        ActiveDirectoryRights.GenericRead,
                        AccessControlType.Allow);

                // Remove existing rules if exist
                security.RemoveAccessRuleSpecific(allowOpenAddressBook);
                security.RemoveAccessRuleSpecific(allowRead);

                // Add a new access rule to allow users in Security Group to open address book.
                security.AddAccessRule(allowOpenAddressBook);
                // Add a new access rule to allow users in Security Group to read object.
                security.AddAccessRule(allowRead);

                // Commit the changes.
                objEntry.CommitChanges();
            }

            ExchangeLog.LogEnd("AdjustADSecurity");
        }
示例#19
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);
        }
示例#20
0
        internal override void SetJournalRuleInternal(ExchangeJournalRule rule)
        {
            ExchangeLog.LogStart("SetJournalRule");
            ExchangeLog.DebugInfo("journalEmail: {0}", rule.JournalEmailAddress);

            Runspace runSpace = null;

            try
            {
                runSpace = OpenRunspace();
                Command cmd;
                if (rule.Enabled)
                {
                    cmd = new Command("Enable-JournalRule");
                    cmd.Parameters.Add("Identity", rule.Name);
                    ExecuteShellCommand(runSpace, cmd);
                }
                else
                {
                    cmd = new Command("Disable-JournalRule");
                    cmd.Parameters.Add("Identity", rule.Name);
                    ExecuteShellCommand(runSpace, cmd);
                }
                cmd = new Command("Set-JournalRule");
                cmd.Parameters.Add("Identity", rule.Name);
                cmd.Parameters.Add("Scope", rule.Scope);
                cmd.Parameters.Add("Recipient", rule.Recipient);
                ExecuteShellCommand(runSpace, cmd);
                ExchangeLog.LogEnd("SetJournalRule");
            }
            catch (Exception ex)
            {
                ExchangeLog.LogError("SetJournalRule", ex);
                throw;
            }
            finally
            {
                CloseRunspace(runSpace);
            }
        }
示例#21
0
        public override ResultObject SetPicture(string accountName, byte[] picture)
        {
            ExchangeLog.LogStart("SetPicture");

            ResultObject res = new ResultObject()
            {
                IsSuccess = true
            };

            Runspace runSpace = null;

            try
            {
                runSpace = OpenRunspace();
                Command cmd;

                if (picture == null)
                {
                    cmd = new Command("Set-Mailbox");
                    cmd.Parameters.Add("Identity", accountName);
                    cmd.Parameters.Add("RemovePicture", true);
                }
                else
                {
                    cmd = new Command("Import-RecipientDataProperty");
                    cmd.Parameters.Add("Identity", accountName);
                    cmd.Parameters.Add("Picture", true);
                    cmd.Parameters.Add("FileData", picture);
                }
                ExecuteShellCommand(runSpace, cmd, res, true);
            }
            finally
            {
                CloseRunspace(runSpace);
            }
            ExchangeLog.LogEnd("SetPicture");

            return(res);
        }
示例#22
0
        public override BytesResult GetPicture(string accountName)
        {
            ExchangeLog.LogStart("GetPicture");

            BytesResult res = new BytesResult()
            {
                IsSuccess = true
            };

            Runspace runSpace = null;

            try
            {
                runSpace = OpenRunspace();

                Command cmd;

                cmd = new Command("Export-RecipientDataProperty");
                cmd.Parameters.Add("Identity", accountName);
                cmd.Parameters.Add("Picture", true);
                Collection <PSObject> result = ExecuteShellCommand(runSpace, cmd, res, true);

                if (result.Count > 0)
                {
                    res.Value =
                        ((Microsoft.Exchange.Data.BinaryFileDataObject)
                             (result[0].ImmediateBaseObject)).FileData;
                }
            }
            finally
            {
                CloseRunspace(runSpace);
            }
            ExchangeLog.LogEnd("GetPicture");

            return(res);
        }
示例#23
0
        internal override ExchangeJournalRule GetJournalRuleInternal(string journalEmail)
        {
            ExchangeJournalRule ret = new ExchangeJournalRule();

            ExchangeLog.LogStart("GetJournalRule");
            ExchangeLog.DebugInfo("journalEmail: {0}", journalEmail);

            Runspace runSpace = null;

            try
            {
                runSpace = OpenRunspace();
                Command cmd = new Command("Get-JournalRule");
                cmd.Parameters.Add("Identity", GetJournalRuleName(journalEmail));
                Collection <PSObject> result = ExecuteShellCommand(runSpace, cmd);
                ExchangeLog.LogEnd("GetJournalRule");
                if (result.Count == 0)
                {
                    return(null);
                }
                ret.Name = ObjToString(GetPSObjectProperty(result[0], "Name"));
                ret.JournalEmailAddress = ObjToString(GetPSObjectProperty(result[0], "JournalEmailAddress"));
                ret.Recipient           = ObjToString(GetPSObjectProperty(result[0], "Recipient"));
                ret.Scope   = ObjToString(GetPSObjectProperty(result[0], "Scope"));
                ret.Enabled = ObjToBoolean(GetPSObjectProperty(result[0], "Enabled"));
                return(ret);
            }
            catch (Exception ex)
            {
                ExchangeLog.LogError("GetJournalRule", ex);
                throw;
            }
            finally
            {
                CloseRunspace(runSpace);
            }
        }
示例#24
0
        internal override ExchangeMailbox GetMailboxAdvancedSettingsInternal(string accountName)
        {
            ExchangeLog.LogStart("GetMailboxAdvancedSettingsInternal");
            ExchangeLog.DebugInfo("Account: {0}", accountName);

            ExchangeMailbox info = new ExchangeMailbox();

            info.AccountName = accountName;
            Runspace runSpace = null;

            try
            {
                runSpace = OpenRunspace();

                Collection <PSObject> result = GetMailboxObject(runSpace, accountName);
                PSObject mailbox             = result[0];

                info.IssueWarningKB =
                    ConvertUnlimitedToKB((Unlimited <ByteQuantifiedSize>)GetPSObjectProperty(mailbox, "IssueWarningQuota"));
                info.ProhibitSendKB =
                    ConvertUnlimitedToKB((Unlimited <ByteQuantifiedSize>)GetPSObjectProperty(mailbox, "ProhibitSendQuota"));
                info.ProhibitSendReceiveKB =
                    ConvertUnlimitedToKB((Unlimited <ByteQuantifiedSize>)GetPSObjectProperty(mailbox, "ProhibitSendReceiveQuota"));
                info.KeepDeletedItemsDays =
                    ConvertEnhancedTimeSpanToDays((EnhancedTimeSpan)GetPSObjectProperty(mailbox, "RetainDeletedItemsFor"));

                info.EnableLitigationHold = (bool)GetPSObjectProperty(mailbox, "LitigationHoldEnabled");

                info.RecoverabelItemsSpace =
                    ConvertUnlimitedToKB((Unlimited <ByteQuantifiedSize>)GetPSObjectProperty(mailbox, "RecoverableItemsQuota"));
                info.RecoverabelItemsWarning =
                    ConvertUnlimitedToKB((Unlimited <ByteQuantifiedSize>)GetPSObjectProperty(mailbox, "RecoverableItemsWarningQuota"));


                //Client Access
                Command cmd = new Command("Get-CASMailbox");
                cmd.Parameters.Add("Identity", accountName);
                result  = ExecuteShellCommand(runSpace, cmd);
                mailbox = result[0];

                info.EnableActiveSync = (bool)GetPSObjectProperty(mailbox, "ActiveSyncEnabled");
                info.EnableOWA        = (bool)GetPSObjectProperty(mailbox, "OWAEnabled");
                info.EnableMAPI       = (bool)GetPSObjectProperty(mailbox, "MAPIEnabled");
                info.EnablePOP        = (bool)GetPSObjectProperty(mailbox, "PopEnabled");
                info.EnableIMAP       = (bool)GetPSObjectProperty(mailbox, "ImapEnabled");

                //Statistics
                cmd = new Command("Get-MailboxStatistics");
                cmd.Parameters.Add("Identity", accountName);
                result = ExecuteShellCommand(runSpace, cmd);
                if (result.Count > 0)
                {
                    PSObject statistics = result[0];
                    Unlimited <ByteQuantifiedSize> totalItemSize =
                        (Unlimited <ByteQuantifiedSize>)GetPSObjectProperty(statistics, "TotalItemSize");
                    info.TotalSizeMB = ConvertUnlimitedToMB(totalItemSize);
                    uint?itemCount = (uint?)GetPSObjectProperty(statistics, "ItemCount");
                    info.TotalItems = ConvertNullableToInt32(itemCount);
                    DateTime?lastLogoffTime = (DateTime?)GetPSObjectProperty(statistics, "LastLogoffTime");;
                    DateTime?lastLogonTime  = (DateTime?)GetPSObjectProperty(statistics, "LastLogonTime");;
                    info.LastLogoff = ConvertNullableToDateTime(lastLogoffTime);
                    info.LastLogon  = ConvertNullableToDateTime(lastLogonTime);
                }
                else
                {
                    info.TotalSizeMB = 0;
                    info.TotalItems  = 0;
                    info.LastLogoff  = DateTime.MinValue;
                    info.LastLogon   = DateTime.MinValue;
                }

                //domain
                info.Domain = GetNETBIOSDomainName();
            }
            finally
            {
                CloseRunspace(runSpace);
            }
            ExchangeLog.LogEnd("GetMailboxAdvancedSettingsInternal");
            return(info);
        }
示例#25
0
        internal override bool DeleteOrganizationInternal(string organizationId, string distinguishedName,
                                                          string globalAddressList, string addressList, string roomList, string offlineAddressBook, string securityGroup, string addressBookPolicy, List <ExchangeDomainName> acceptedDomains)
        {
            ExchangeLog.LogStart("DeleteOrganizationInternal");
            bool ret = true;

            Runspace runSpace = null;

            try
            {
                runSpace = OpenRunspace();


                string ou = ConvertADPathToCanonicalName(distinguishedName);

                if (!DeleteOrganizationMailboxes(runSpace, ou))
                {
                    ret = false;
                }

                if (!DeleteOrganizationContacts(runSpace, ou))
                {
                    ret = false;
                }

                if (!DeleteOrganizationDistributionLists(runSpace, ou))
                {
                    ret = false;
                }

                //delete AddressBookPolicy
                try
                {
                    if (!string.IsNullOrEmpty(addressBookPolicy))
                    {
                        DeleteAddressBookPolicy(runSpace, addressBookPolicy);
                    }
                }
                catch (Exception ex)
                {
                    ret = false;
                    ExchangeLog.LogError("Could not delete AddressBook Policy " + addressBookPolicy, ex);
                }

                //delete OAB
                try
                {
                    if (!string.IsNullOrEmpty(offlineAddressBook))
                    {
                        DeleteOfflineAddressBook(runSpace, offlineAddressBook);
                    }
                }
                catch (Exception ex)
                {
                    ret = false;
                    ExchangeLog.LogError("Could not delete Offline Address Book " + offlineAddressBook, ex);
                }

                //delete AL
                try
                {
                    if (!string.IsNullOrEmpty(addressList))
                    {
                        DeleteAddressList(runSpace, addressList);
                    }
                }
                catch (Exception ex)
                {
                    ret = false;
                    ExchangeLog.LogError("Could not delete Address List " + addressList, ex);
                }

                //delete RL
                try
                {
                    if (!string.IsNullOrEmpty(roomList))
                    {
                        DeleteAddressList(runSpace, roomList);
                    }
                }
                catch (Exception ex)
                {
                    ret = false;
                    ExchangeLog.LogError("Could not delete Address List " + roomList, ex);
                }


                //delete GAL
                try
                {
                    if (!string.IsNullOrEmpty(globalAddressList))
                    {
                        DeleteGlobalAddressList(runSpace, globalAddressList);
                    }
                }
                catch (Exception ex)
                {
                    ret = false;
                    ExchangeLog.LogError("Could not delete Global Address List " + globalAddressList, ex);
                }

                //delete ActiveSync policy
                try
                {
                    DeleteActiveSyncPolicy(runSpace, organizationId);
                }
                catch (Exception ex)
                {
                    ret = false;
                    ExchangeLog.LogError("Could not delete ActiveSyncPolicy " + organizationId, ex);
                }

                //disable mail security distribution group
                try
                {
                    DisableMailSecurityDistributionGroup(runSpace, securityGroup);
                }
                catch (Exception ex)
                {
                    ret = false;
                    ExchangeLog.LogError("Could not disable mail security distribution group " + securityGroup, ex);
                }

                if (!DeleteOrganizationAcceptedDomains(runSpace, acceptedDomains))
                {
                    ret = false;
                }
            }
            catch (Exception ex)
            {
                ret = false;
                ExchangeLog.LogError("DeleteOrganizationInternal", ex);
                throw;
            }
            finally
            {
                CloseRunspace(runSpace);
            }
            ExchangeLog.LogEnd("DeleteOrganizationInternal");
            return(ret);
        }
示例#26
0
        internal string GetDatabase(Runspace runSpace, string primaryDomainController, string dagName)
        {
            string database = string.Empty;

            if (string.IsNullOrEmpty(dagName))
            {
                return(string.Empty);
            }

            ExchangeLog.LogStart("GetDatabase");
            ExchangeLog.LogInfo("DAG: " + dagName);

            // this part of code handles mailboxnames like in the old 2007 provider
            // check if DAG is in reality DAG\mailboxdatabase
            string dagNameDAG      = string.Empty;
            string dagNameMBX      = string.Empty;
            bool   isFixedDatabase = false;

            if (dagName.Contains("\\"))
            {
                // split the two parts and extract DAG-Name and mailboxdatabase-name
                string[] parts = dagName.Split(new char[] { '\\' }, 2, StringSplitOptions.None);
                dagNameDAG = parts[0];
                dagNameMBX = parts[1];
                // check that we realy have a database name
                if (!String.IsNullOrEmpty(dagNameMBX))
                {
                    isFixedDatabase = true;
                }
            }
            else
            {
                // there is no mailboxdatabase-name use the loadbalancing-code
                dagNameDAG      = dagName;
                isFixedDatabase = false;
            }

            //Get Dag Servers - with the name of the database availability group
            Collection <PSObject> dags = null;
            Command cmd = new Command("Get-DatabaseAvailabilityGroup");

            cmd.Parameters.Add("Identity", dagNameDAG);
            dags = ExecuteShellCommand(runSpace, cmd);

            if (htBbalancer == null)
            {
                htBbalancer = new Hashtable();
            }

            // use fully qualified dagName for loadbalancer. Thus if there are two services and one of them
            // contains only the DAG, the "fixed" database could also be used in loadbalancing. If you do not want this,
            // set either IsExcludedFromProvisioning or IsSuspendedFromProvisioning - it is not evaluated for fixed databases
            if (htBbalancer[dagName] == null)
            {
                htBbalancer.Add(dagName, 0);
            }

            if (dags != null && dags.Count > 0)
            {
                ADMultiValuedProperty <ADObjectId> servers = (ADMultiValuedProperty <ADObjectId>)GetPSObjectProperty(dags[0], "Servers");

                if (servers != null)
                {
                    System.Collections.Generic.List <string> lstDatabase = new System.Collections.Generic.List <string>();

                    if (!isFixedDatabase) // "old" loadbalancing code
                    {
                        foreach (object objServer in servers)
                        {
                            Collection <PSObject> databases = null;
                            cmd = new Command("Get-MailboxDatabase");
                            cmd.Parameters.Add("Server", ObjToString(objServer));
                            databases = ExecuteShellCommand(runSpace, cmd);

                            foreach (PSObject objDatabase in databases)
                            {
                                if (((bool)GetPSObjectProperty(objDatabase, "IsExcludedFromProvisioning") == false) &&
                                    ((bool)GetPSObjectProperty(objDatabase, "IsSuspendedFromProvisioning") == false))
                                {
                                    string db = ObjToString(GetPSObjectProperty(objDatabase, "Identity"));

                                    bool bAdd = true;
                                    foreach (string s in lstDatabase)
                                    {
                                        if (s.ToLower() == db.ToLower())
                                        {
                                            bAdd = false;
                                            break;
                                        }
                                    }

                                    if (bAdd)
                                    {
                                        lstDatabase.Add(db);
                                        ExchangeLog.LogInfo("AddDatabase: " + db);
                                    }
                                }
                            }
                        }
                    }
                    else // new fixed database code
                    {
                        Collection <PSObject> databases = null;
                        cmd = new Command("Get-MailboxDatabase");
                        cmd.Parameters.Add("Identity", dagNameMBX);
                        databases = ExecuteShellCommand(runSpace, cmd);

                        // do not check "IsExcludedFromProvisioning" or "IsSuspended", just check if it is a member of the DAG
                        foreach (PSObject objDatabase in databases)
                        {
                            string dagSetting = ObjToString(GetPSObjectProperty(objDatabase, "MasterServerOrAvailabilityGroup"));
                            if (dagNameDAG.Equals(dagSetting, StringComparison.OrdinalIgnoreCase))
                            {
                                lstDatabase.Add(dagNameMBX);
                                ExchangeLog.LogInfo("AddFixedDatabase: " + dagNameMBX);
                            }
                        }
                    }

                    int balancer = (int)htBbalancer[dagName];
                    balancer++;
                    if (balancer >= lstDatabase.Count)
                    {
                        balancer = 0;
                    }
                    htBbalancer[dagName] = balancer;
                    if (lstDatabase.Count != 0)
                    {
                        database = lstDatabase[balancer];
                    }
                }
            }

            ExchangeLog.LogEnd("GetDatabase");
            return(database);
        }
示例#27
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);
            }
        }
示例#28
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);
        }
示例#29
0
        internal override ExchangeMailbox GetMailboxGeneralSettingsInternal(string accountName)
        {
            ExchangeLog.LogStart("GetMailboxGeneralSettingsInternal");
            ExchangeLog.DebugInfo("Account: {0}", accountName);

            ExchangeMailbox info = new ExchangeMailbox();

            info.AccountName = accountName;
            Runspace runSpace = null;

            try
            {
                runSpace = OpenRunspace();

                Collection <PSObject> result = GetMailboxObject(runSpace, accountName);
                PSObject mailbox             = result[0];

                string         id    = GetResultObjectDN(result);
                string         path  = AddADPrefix(id);
                DirectoryEntry entry = GetADObject(path);


                //ADAccountOptions userFlags = (ADAccountOptions)entry.Properties["userAccountControl"].Value;
                //info.Disabled = ((userFlags & ADAccountOptions.UF_ACCOUNTDISABLE) != 0);
                info.Disabled = (bool)entry.InvokeGet("AccountDisabled");

                info.DisplayName          = (string)GetPSObjectProperty(mailbox, "DisplayName");
                info.HideFromAddressBook  = (bool)GetPSObjectProperty(mailbox, "HiddenFromAddressListsEnabled");
                info.EnableLitigationHold = (bool)GetPSObjectProperty(mailbox, "LitigationHoldEnabled");

                Command cmd = new Command("Get-User");
                cmd.Parameters.Add("Identity", accountName);
                result = ExecuteShellCommand(runSpace, cmd);
                PSObject user = result[0];

                info.FirstName = (string)GetPSObjectProperty(user, "FirstName");
                info.Initials  = (string)GetPSObjectProperty(user, "Initials");
                info.LastName  = (string)GetPSObjectProperty(user, "LastName");

                info.Address    = (string)GetPSObjectProperty(user, "StreetAddress");
                info.City       = (string)GetPSObjectProperty(user, "City");
                info.State      = (string)GetPSObjectProperty(user, "StateOrProvince");
                info.Zip        = (string)GetPSObjectProperty(user, "PostalCode");
                info.Country    = CountryInfoToString((CountryInfo)GetPSObjectProperty(user, "CountryOrRegion"));
                info.JobTitle   = (string)GetPSObjectProperty(user, "Title");
                info.Company    = (string)GetPSObjectProperty(user, "Company");
                info.Department = (string)GetPSObjectProperty(user, "Department");
                info.Office     = (string)GetPSObjectProperty(user, "Office");


                info.ManagerAccount = GetManager(entry); //GetExchangeAccount(runSpace, ObjToString(GetPSObjectProperty(user, "Manager")));
                info.BusinessPhone  = (string)GetPSObjectProperty(user, "Phone");
                info.Fax            = (string)GetPSObjectProperty(user, "Fax");
                info.HomePhone      = (string)GetPSObjectProperty(user, "HomePhone");
                info.MobilePhone    = (string)GetPSObjectProperty(user, "MobilePhone");
                info.Pager          = (string)GetPSObjectProperty(user, "Pager");
                info.WebPage        = (string)GetPSObjectProperty(user, "WebPage");
                info.Notes          = (string)GetPSObjectProperty(user, "Notes");
            }
            finally
            {
                CloseRunspace(runSpace);
            }
            ExchangeLog.LogEnd("GetMailboxGeneralSettingsInternal");
            return(info);
        }
示例#30
0
        internal override ExchangeMailboxStatistics GetMailboxStatisticsInternal(string id)
        {
            ExchangeLog.LogStart("GetMailboxStatisticsInternal");
            ExchangeLog.DebugInfo("Account: {0}", id);

            ExchangeMailboxStatistics info = new ExchangeMailboxStatistics();
            Runspace runSpace = null;

            try
            {
                runSpace = OpenRunspace();

                Collection <PSObject> result = GetMailboxObject(runSpace, id);
                PSObject mailbox             = result[0];

                string         dn    = GetResultObjectDN(result);
                string         path  = AddADPrefix(dn);
                DirectoryEntry entry = GetADObject(path);
                info.Enabled = !(bool)entry.InvokeGet("AccountDisabled");
                info.LitigationHoldEnabled = (bool)GetPSObjectProperty(mailbox, "LitigationHoldEnabled");

                info.DisplayName = (string)GetPSObjectProperty(mailbox, "DisplayName");
                SmtpAddress smtpAddress = (SmtpAddress)GetPSObjectProperty(mailbox, "PrimarySmtpAddress");
                if (smtpAddress != null)
                {
                    info.PrimaryEmailAddress = smtpAddress.ToString();
                }

                info.MaxSize = ConvertUnlimitedToBytes((Unlimited <ByteQuantifiedSize>)GetPSObjectProperty(mailbox, "ProhibitSendReceiveQuota"));
                info.LitigationHoldMaxSize = ConvertUnlimitedToBytes((Unlimited <ByteQuantifiedSize>)GetPSObjectProperty(mailbox, "RecoverableItemsQuota"));

                DateTime?whenCreated = (DateTime?)GetPSObjectProperty(mailbox, "WhenCreated");
                info.AccountCreated = ConvertNullableToDateTime(whenCreated);
                //Client Access
                Command cmd = new Command("Get-CASMailbox");
                cmd.Parameters.Add("Identity", id);
                result  = ExecuteShellCommand(runSpace, cmd);
                mailbox = result[0];

                info.ActiveSyncEnabled = (bool)GetPSObjectProperty(mailbox, "ActiveSyncEnabled");
                info.OWAEnabled        = (bool)GetPSObjectProperty(mailbox, "OWAEnabled");
                info.MAPIEnabled       = (bool)GetPSObjectProperty(mailbox, "MAPIEnabled");
                info.POPEnabled        = (bool)GetPSObjectProperty(mailbox, "PopEnabled");
                info.IMAPEnabled       = (bool)GetPSObjectProperty(mailbox, "ImapEnabled");

                //Statistics
                cmd = new Command("Get-MailboxStatistics");
                cmd.Parameters.Add("Identity", id);
                result = ExecuteShellCommand(runSpace, cmd);
                if (result.Count > 0)
                {
                    PSObject statistics = result[0];
                    Unlimited <ByteQuantifiedSize> totalItemSize = (Unlimited <ByteQuantifiedSize>)GetPSObjectProperty(statistics, "TotalItemSize");
                    info.TotalSize = ConvertUnlimitedToBytes(totalItemSize);

                    uint?itemCount = (uint?)GetPSObjectProperty(statistics, "ItemCount");
                    info.TotalItems = ConvertNullableToInt32(itemCount);

                    DateTime?lastLogoffTime = (DateTime?)GetPSObjectProperty(statistics, "LastLogoffTime");
                    DateTime?lastLogonTime  = (DateTime?)GetPSObjectProperty(statistics, "LastLogonTime");
                    info.LastLogoff = ConvertNullableToDateTime(lastLogoffTime);
                    info.LastLogon  = ConvertNullableToDateTime(lastLogonTime);
                }
                else
                {
                    info.TotalSize  = 0;
                    info.TotalItems = 0;
                    info.LastLogoff = DateTime.MinValue;
                    info.LastLogon  = DateTime.MinValue;
                }

                if (info.LitigationHoldEnabled)
                {
                    cmd = new Command("Get-MailboxFolderStatistics");
                    cmd.Parameters.Add("FolderScope", "RecoverableItems");
                    cmd.Parameters.Add("Identity", id);
                    result = ExecuteShellCommand(runSpace, cmd);
                    if (result.Count > 0)
                    {
                        PSObject           statistics    = result[0];
                        ByteQuantifiedSize totalItemSize = (ByteQuantifiedSize)GetPSObjectProperty(statistics, "FolderAndSubfolderSize");
                        info.LitigationHoldTotalSize = (totalItemSize == null) ? 0 : ConvertUnlimitedToBytes(totalItemSize);

                        Int32 itemCount = (Int32)GetPSObjectProperty(statistics, "ItemsInFolder");
                        info.LitigationHoldTotalItems = (itemCount == 0) ? 0 : itemCount;
                    }
                }
                else
                {
                    info.LitigationHoldTotalSize  = 0;
                    info.LitigationHoldTotalItems = 0;
                }
            }
            finally
            {
                CloseRunspace(runSpace);
            }
            ExchangeLog.LogEnd("GetMailboxStatisticsInternal");
            return(info);
        }