0

ここでユーザーのマネージャー プロパティを編集できる関数があります。

 Public Shared Sub SetManagerProperty(ByVal de As DirectoryEntry, ByVal pName As String, ByVal pValue As String)


        'First make sure the property value isnt "nothing"
        If Not pValue Is Nothing Then
            'Check to see if the DirectoryEntry contains this property already
            If de.Properties.Contains(pName) Then   'The DE contains this property
                'Update the properties value
                de.Properties(pName)(0) = pValue
            Else    'Property doesnt exist
                'Add the property and set it's value

                'de.Properties(pName).Add("cn=" & frmOrganization.txtManagerName.Text & ",OU=Company,OU=Users,OU=Summit,OU=North America,DC=mycompany,DC=com")


            End If
        End If

    End Sub

しかし、マネージャーが Company OU にいない場合はどうなるでしょうか。これを編集して、ドメイン全体で彼を検索するにはどうすればよいですか?

4

1 に答える 1

0

DirectorySearcherオブジェクトを使用する

DirectorySearcher ds = new DirectorySearcher();
ds.SearchRoot = new DirectoryEntry(String.Format("LDAP://{0}/{1}",adserver,searchroot));
ds.PropertiesToLoad.Add("distinguishedName");
ds.SearchScope = SearchScope.Subtree;
ds.Filter = String.Format("(&(objectCategory=user)(sAMAccountName={0}))", frmOrganization.txtManagerName.Text);
SearchResult sr = ds.FindOne();
if (sr == null)
{
    // Manager does not exist
    return null;
}
String managerDN = sr.Properties["distinguishedName"][0].ToString();
于 2012-04-06T15:38:11.157 に答える