vbs ldap查询问题 [英] vbs ldap query issues
本文介绍了vbs ldap查询问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在尝试利用我的脚本知识,通过ldap搜索基于变量的用户,然后获取该用户的显示名称. 到目前为止,我在下面看到了我的消息
i am currently trying to use my small knowledge of scripting to search through ldap find a user based on a variable then get my the displayname for that user. so far i ahve the below and im stuck
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
=请帮助!
我梳理了上面的内容,现在正在尝试,但是出现语法错误
I scartached the above and am now trying this but get syntax errors
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")
推荐答案
最终解决了这个问题
设置objConnection = CreateObject("ADODB.Connection")
Set 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
这篇关于vbs ldap查询问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文