我需要使用displayname执行LDAP查询的vbscript,并为我检索SamAccountName。
答案 0 :(得分:0)
这样的事情应该这样做:
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Open "Provider=ADsDSOObject;"
objCommand.ActiveConnection = objConnection
strDomainName = "dc=YOURDOMAIN,dc=com"
strUserCN = "FIRSTNAME LASTNAME"
objCommand.CommandText = "<LDAP://" & strDomainName & ">;(&(objectCategory=person)(objectClass=user)(cn=" & strUserCN & "));samAccountName;subtree"
Set objRecordSet = objCommand.Execute
If Not objRecordset.EOF Then
WScript.Echo objRecordSet.Fields("samAccountName")
End If
objConnection.Close
Set objRecordSet = Nothing
Set objConnection = Nothing
Set objCommand = Nothing
答案 1 :(得分:0)
很棒的脚本(并且比较喜欢)但是目前只显示记录集中的第一个结果 - 显示输出位需要更像这样的东西:
DO until objRecordset.EOF = TRUE
WScript.Echo objRecordSet.Fields("samAccountName")
objRecordSet.MoveNext
Loop