MS.Tech - ???????

.NET & 微软企业服务器 & 前沿技术和产品
随笔 - 92, 评论 - 1040, 引用 - 87

导航

关于

所有内容和观点仅代表个人观点,如有问题和建议请发Email给我。

标签

每月存档

最新留言

广告

 

通过以下代码枚举列出所有的Exchange Server、StoreGroups和MailStore,并获取每个MailStore中Mailbox的数量。本段C#代码为http://www.ureader.com/message/513012.aspx一文中的VBNET代码改写而成,在Exchange 2003环境中测试通过。

通过这段代码,结合创建 Mailbox 的代码,可以实现获取Exchange环境的Server、StoreGroup、MailStore和Mailbox信息,或在指定Store(比如在所有Store中最少Mailbox的那个,或者人为指定目标Store)中创建Mailbox。

        protected void Page_Load(object sender, EventArgs e)

        {

            DirectoryEntry RootDSE = new DirectoryEntry("LDAP://RootDSE");

            string rootPath = "LDAP://" + RootDSE.Properties["configurationNamingContext"].Value.ToString();

            DirectoryEntry configContainer = new DirectoryEntry(rootPath);

 

            DirectorySearcher configSearcher = new DirectorySearcher(configContainer);

            configSearcher.SearchRoot = configContainer;

            configSearcher.Filter = "(objectCategory=msExchExchangeServer)";

 

            // Enumerate all Exchange Servers

            SearchResultCollection serverResults = configSearcher.FindAll();

            foreach (SearchResult serverResult in serverResults)

            {

                Response.Write("<br/><br/><font color=\"red\">=== Exchange Server: " + serverResult.GetDirectoryEntry().Properties["cn"].Value.ToString() + " ===</font><br/><br/>");

 

                SearchResultCollection storeGroups;

                SearchResultCollection stores;

                int mailboxCount;

 

                // Enumerate all Store Groups

                storeGroups = SearchContainer(serverResult.Properties["distinguishedName"][0].ToString(),

                    "(objectCategory=msExchStorageGroup)");

                foreach (SearchResult storeGroup in storeGroups)

                {

                    string storeGroupName = storeGroup.GetDirectoryEntry().Properties["cn"].Value.ToString();

                    Response.Write(storeGroupName + "<br/>");

 

                    mailboxCount = 0;

 

                    // Enumerate All Stores

                    stores = SearchContainer(storeGroup.Properties["distinguishedName"][0].ToString(),

                        "(objectCategory=msExchPrivateMDB)");

                    foreach (SearchResult store in stores)

                    {

                        Response.Write("&nbsp;&nbsp;" + store.GetDirectoryEntry().Properties["cn"].Value.ToString() + "<br/>");

                        Response.Write("&nbsp;&nbsp;&nbsp;&nbsp;Number of Mailboxes: " +

                            store.GetDirectoryEntry().Properties["homeMDBBL"].Count.ToString() + "<br/>");

 

                        mailboxCount += store.GetDirectoryEntry().Properties["homeMDBBL"].Count;

                    }

 

                    string reportMsg = String.Format("Total Number of Mailboxes in Storage Group({0}): {1}<br/><br/>", storeGroupName, mailboxCount);

                    Response.Write(reportMsg);

                }

            }

        }

 

        private SearchResultCollection SearchContainer(string srvPath, string strFilter)

        {

            string ldapPath = "LDAP://" + srvPath;

            DirectoryEntry serverContainer = new DirectoryEntry(ldapPath);

 

            DirectorySearcher serverSearcher = new DirectorySearcher(serverContainer);

            serverSearcher.Filter = strFilter;

            serverSearcher.SearchScope = SearchScope.Subtree;

 

            serverSearcher.PropertiesToLoad.Add("cn");

            serverSearcher.PropertiesToLoad.Add("distinguishedName");

            serverSearcher.PropertiesToLoad.Add("homeMDBBL");

 

            SearchResultCollection results = serverSearcher.FindAll();

 

            return results;

        }


关于Exchange的收藏夹几个必备站点:

打印 | 张贴于 2007-03-04 01:49:00 | Tag:微软企业服务器

留言反馈

#回复: 枚举Exchange Server、SotreGroups和MailStore 编辑
比较吃力,看起来!收藏了,慢慢研究!
2007-11-21 15:09:00 | [匿名用户:国际长途电话卡]
#回复: 枚举Exchange Server、SotreGroups和MailStore 编辑
感觉好复杂啊。。。。。
2007-10-01 00:23:00 | [匿名用户:火狐]
#AD 用户组类库中增加几个功能 编辑
以前弄个了用于AD OU、帐号和组等对象的几个类(见《 活动目录操作类更新 》),现在对这个再进行一点改进和增加一些功能。貌似gotdotnet workspace已经无法使用,过些日子我把更新后的类库发布在codeplex上再发布个具体链接出来
2007-07-22 04:03:00 | [匿名用户:Joycode@Ab110.com]
#回复: 枚举Exchange Server、SotreGroups和MailStore 编辑
顶 太好了 值得学习 呵呵
2007-07-21 15:54:00 | [匿名用户:火狐]
#回复: 枚举Exchange Server、SotreGroups和MailStore 编辑
顶 太好的文章了 多谢楼主
2007-07-21 15:53:00 | [匿名用户:火狐]
#回复: 枚举Exchange Server、SotreGroups和MailStore 编辑
谢谢 太好了
2007-07-21 15:52:00 | [匿名用户:火狐]
#回复: 枚举Exchange Server、SotreGroups和MailStore 编辑
谢谢 太好了 哈哈哈哈哈
2007-07-21 15:52:00 | [匿名用户:火狐]
#回复: 枚举Exchange Server、SotreGroups和MailStore 编辑
好程序。
2007-03-26 12:28:00 | [匿名用户:firefox]
对不起,目前本随笔不允许发表新评论.

Powered by: Joycode.MVC引擎 0.5.1.8