1

我目前正在尝试使用我对脚本编写的小知识通过 ldap 进行搜索,根据变量查找用户,然后获取该用户的显示名称。到目前为止,我在下面,我被卡住了

On Error Resume Next

Dim objNetwork 
Dim userName   

  Set objNetwork = CreateObject("WScript.Network") 
  userName = objNetwork.UserName   
  WScript.Echo userName 


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

     objCommand.Properties("Page Size") = 1000

        objCommand.CommandText =  _
  "<LDAP://dc=domain,dc=com>;(objectCategory=User);Name;Subtree"  
Set objRecordSet = objCommand.Execute

 objRecordSet.MoveFirst

  Do Until objRecordSet.Fields("Name").Value = username

  objRecordSet.MoveNext
  Loop

  Wscript.Echo objRecordSet.Fields("Name").Value

= 请帮忙!!

我对上述内容进行了检查,现在正在尝试此操作,但出现语法错误

option explicit dim cmd, cn, rs, objRoot,
set cmd = createobject("ADODB.Command") 
    set cn = createobject("ADODB.Connection") 

set rs = createobject("ADODB.Recordset") 
cn.open "Provider=ADsDSOObject;" 

cmd.activeconnection = cn set 

objRoot = getobject("LDAP://RootDSE") cmd.commandtext = "<LDAP://dn=domain,dn=com">;(&(objectClass=user)(!(objectClass=computer)            (sAMAccountName=first.last))));name,displayname;subtree"

cmd.properties("page size")=1000 set rs = cmd.execute 

wscript.echo rs("name") 
4

2 回答 2

1

最终得到了这个

设置 objConnection = CreateObject("ADODB.Connection")

Set objCommand = CreateObject("ADODB.Command")  

objConnection.Open "Provider=ADsDSOObject;" 
objCommand.ActiveConnection = objConnection  

strDomainName = "dc=domain,dc=com" 
strUserCN = username 
objCommand.CommandText = "<LDAP://" & strDomainName & ">;(&(objectCategory=person)     (objectClass=user)(cn=" & strUserCN & "));displayName;subtree"  

Set objRecordSet = objCommand.Execute  

If Not objRecordset.EOF Then  

strray = split(objRecordSet.Fields("displayName"),"(") 
strdat = strray(0)



username = trim(strdat)

End If  
于 2012-09-10T13:54:32.693 回答
1

我怀疑属性名称是名称,并在此行中尝试显示名称:

"<LDAP://dc=domain,dc=com>;(objectCategory=User);Name;Subtree" 
于 2012-09-07T17:20:26.043 回答