如何使用AD中的LDAP查询从MS Exchange Server 2010获取DAG信息?

时间:2011-12-07 13:33:32

标签: active-directory exchange-server exchange-server-2010 ldap-query

我想知道用于获取有关Exchange Server的更多信息的LDAP查询。 我有兴趣了解有关数据可用性组,有关它们的统计信息和复制状态等的更多信息。 我知道有一些CmdLets但我想避免使用PowerShell。

我想知道从Active Directory for Exchange Server获取相同信息的任何可能方法。

1 个答案:

答案 0 :(得分:0)

这是一个很酷的主意!

它位于配置分区下面:

  

CN = Microsoft Exchange,CN =服务,CN =配置,DC = xx,DC = xx。

下面的C#代码将检索服务器角色,并且应该可以帮助您入门。

角色信息来自here

        using (DirectoryEntry de = new DirectoryEntry("LDAP://RootDSE"))
        {
            var NamingContext = de.Properties["configurationNamingContext"][0];
            using (DirectoryEntry de_NC = new DirectoryEntry("LDAP://" + NamingContext))
            {
                using (DirectorySearcher ds = new DirectorySearcher(de_NC))
                {
                    ds.PropertiesToLoad.Add("cn");

                    ds.Filter = "(&(objectCategory=msExchExchangeServer)(msExchCurrentServerRoles:1.2.840.113556.1.4.803:=2))";
                    Output("Mailbox Role Servers:", ds, "cn");

                    ds.Filter = "(&(objectCategory=msExchExchangeServer)(msExchCurrentServerRoles:1.2.840.113556.1.4.803:=4))";
                    Output("CAS Role Servers:", ds, "cn");

                    ds.Filter = "(&(objectCategory=msExchExchangeServer)(msExchCurrentServerRoles:1.2.840.113556.1.4.803:=16))";
                    Output("Unified Messaging Role Servers:", ds, "cn");

                    ds.Filter = "(&(objectCategory=msExchExchangeServer)(msExchCurrentServerRoles:1.2.840.113556.1.4.803:=32))";
                    Output("Hub Transport Role Servers:", ds, "cn");

                    ds.Filter = "(&(objectCategory=msExchExchangeServer)(msExchCurrentServerRoles:1.2.840.113556.1.4.803:=64))";
                    Output("Edge Transport Role Servers:", ds, "cn");
                }
            }
        }


    static void Output(string Titel, DirectorySearcher ds, string Property)
    {
        Console.WriteLine(Titel);
        SearchResultCollection src = ds.FindAll();
        foreach (SearchResult RoleServer in src)
        {
            Console.WriteLine(RoleServer.Properties[Property][0].ToString());
        }
        if (src.Count < 1)
            Console.WriteLine("---");

        Console.WriteLine();
    }
相关问题