Get list of Computers from Active Directory (LDAP)

Get help with using AutoHotkey and its commands and hotkeys
User avatar
Tomer
Posts: 314
Joined: 21 Aug 2016, 05:11

Get list of Computers from Active Directory (LDAP)

09 Nov 2016, 08:56

Hello

I need help to get list of computers from specific ou (object unit) from Active Directory,
I got this script which getin much info I don't need.

hope its possible!

tnx

Code: Select all

objRootDSE := ComObjGet("LDAP://rootDSE")
strDomain := objRootDSE.Get("defaultNamingContext")
strADPath := "LDAP://" . strDomain
objDomain := ComObjGet(strADPath)

objConnection := ComObjCreate("ADODB.Connection")
objConnection.Open("Provider=ADsDSOObject")
objCommand := ComObjCreate("ADODB.Command")
objCommand.ActiveConnection := objConnection

objFileSystem := ComObjCreate("Scripting.FileSystemObject")
objOutputFile := objFileSystem.CreateTextFile("UserList.csv")

CommandText := "<" . strADPath . ">" . ";(&(objectClass=user))" . ";distinguishedName,sAMAccountName;subtree"
objCommand.CommandText := CommandText

objRecordSet := objCommand.Execute
objRecordCount := objRecordSet.RecordCount
objRecordSet.MoveFirst

While !objRecordSet.EOF
{
strDN := objRecordSet.Fields("distinguishedName").value
userCN := objRecordSet.Fields("sAMAccountName").value

objOutputFile.Write(userCN . ",")
objOutputFile.Write(strDN . ",")
objOutputFile.WriteLine("")

objRecordSet.MoveNext
}

Return to “Ask For Help”

Who is online

Users browsing this forum: labrint, RubbeH and 54 guests