【问题标题】:Setting the manager property in AD without knowing the manager's URL在不知道经理 URL 的情况下在 AD 中设置经理属性
【发布时间】:2012-04-05 15:19:51
【问题描述】:

我有一个功能可以让我在这里编辑用户的 manager 属性:

 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

但如果经理不在公司 OU 中怎么办?我如何编辑它以在整个域中搜索他?

【问题讨论】:

    标签: vb.net active-directory ldap


    【解决方案1】:

    使用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();
    

    【讨论】:

    • 问题是它似乎不喜欢将 SearchResult 转换为字符串。我收到一个未指明的错误。
    • 您是在转换搜索结果还是属性?此外,如果您更习惯使用 DirectoryEntries,还可以使用 SearchResult.GetDirectoryEntry() 选项
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-11
    • 1970-01-01
    • 2014-09-02
    • 2014-11-10
    • 2013-05-10
    • 2021-05-29
    相关资源
    最近更新 更多