1

我编写了这个脚本,它通过 VBscript 从 AD 中提取指定用户的 sAMAccountName,但它似乎只在我自己的 OU 组中工作。这是由于我公司内部的权限限制吗?或者这是由于我在代码中没有看到的东西?

 Dim result
result = getsAMAccountName("Some Name")
msgbox result
Function getsAMAccountName(name)
Dim adoCommand, adoConnection, strBase, strFilter, strAttributes
Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strsAM, objUser

Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
Set adoCommand.ActiveConnection = adoConnection

Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
msgbox strDNSDomain
strBase = "<LDAP://" & strDNSDomain & ">"

'be sure passed var usersel is referenced properly
strFilter = "(cn=" & name & ")"
strAttributes = "distinguishedName"

strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False

Set adoRecordset = adoCommand.Execute

Do Until adoRecordset.EOF

    strsAM = adoRecordset.Fields("distinguishedName").Value
    Set objUser = GetObject("LDAP://" & strsAM)
    getsAMAccountName = objUser.sAMAccountName
    adoRecordset.MoveNext
Loop

adoRecordset.Close
adoConnection.Close
End Function
4

2 回答 2

0

当您在 GetObject 调用中指定 OU 时,它是否有效?

GetObject("LDAP://OU=YourOU,DC=YourDomain,DC=com")

从这个问题Querying Active Directory using VBScript

于 2012-06-11T22:13:09.133 回答
0

最终成为权限,确保在将 LDAP 拉取到 asp classic 时包含/指定 processID 和 PW ......并避免 asp classic

Set adoConnection = CreateObject("ADODB.Connection")                
            adoConnection.Provider = "ADsDSOObject"
                With adoConnection
                    .Properties("User ID") = ' Process ID goes
                    .Properties("Password") = 'password
                    .Properties("encrypt password") = True
                End With

        adoConnection.Open "Active Directory Provider"
        Set adoCommand = CreateObject("ADODB.Command")
        Set adoCommand.ActiveConnection = adoConnection
于 2012-06-14T20:00:19.753 回答