简体   繁体   中英

Get “Home Directory” attribute from active directory

I'm trying to get Home Directory attribute value from active directory..

I used the following code:

public static void GetExchangeServerByWwidLdap(string wwid)
{
    var exchange = string.Empty;

    using (var ds = new DirectorySearcher())
    {
        ds.SearchRoot = new DirectoryEntry("GC:something");
        ds.SearchScope = SearchScope.Subtree;

        //construct search filter
        string filter = "(&(objectclass=user)(objectcategory=person)";
        filter += "(employeeid=" + wwid + "))";
        ds.Filter = filter;

        string[] requiredProperties = new string[] { "homeDirectory", "homemta" };

        foreach (String property in requiredProperties)
            ds.PropertiesToLoad.Add(property);

        SearchResult result = ds.FindOne();
    }      
}

When I check result object data, I'm seeing only 2 values: "homemta" and "adspath". Where is the "homeDirectory" value?

I entered AD website and searched the same values for same users - through the website I can see the all the data I searched for so I assuming that I have code issue somewhere.

What am I doing wrong?

You're trying to retrieve homeDirectory from global catalog.

It's not there.

You can eg bind to the user by ADsPath property (ie “LDAP://…” string), then query the homeDirectory attribute of that user.

Or, if you only have a single domain, you can search within that domain instead of searching the GC. In this case you'll be able to retrieve all the properties you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM