Ghost21 Posted May 21, 2008 Posted May 21, 2008 I have been reading all the LDAP Fourm info . But unable to actually pull information from the server . Do I have to be logged onto that machine to get the info that I request. I would like to pll the information remotely if possible. Thanks
Developers Jos Posted May 21, 2008 Developers Posted May 21, 2008 I have been reading all the LDAP Fourm info . But unable to actually pull information from the server . Do I have to be logged onto that machine to get the info that I request. I would like to pll the information remotely if possible.ThanksCould you be more specific what information you want retrieve? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Ghost21 Posted May 21, 2008 Author Posted May 21, 2008 Could you be more specific what information you want retrieve?Computer NameUser NameFull NameIP EmailMacSo far that if possible... But eventually as much as I can obtain..Thanks
Developers Jos Posted May 21, 2008 Developers Posted May 21, 2008 Computer NameUser NameFull NameIP EmailMacSo far that if possible... But eventually as much as I can obtain..ThanksDo you want to get this info from the AD or the PC itself? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Ghost21 Posted May 21, 2008 Author Posted May 21, 2008 Do you want to get this info from the AD or the PC itself? JosFrom Active Directory
Developers Jos Posted May 21, 2008 Developers Posted May 21, 2008 Something like this should work. You need to add the fields you require but it gets you started. Jos Func _EnumUsers() Local $objCommand = ObjCreate("ADODB.Command") Local $objConnection = ObjCreate("ADODB.Connection") $objConnection.Provider = "ADsDSOObject" $objConnection.Open ("Active Directory Provider") $objCommand.ActiveConnection = $objConnection Local $strBase = "<GC://dc=MyDom,dc=Inc>" Local $strFilter = "(&(objectCategory=person)(objectClass=user)(sAMAccountName=*))" Local $strAttributes = "cn,sAMAccountName,displayName,sn,distinguishedName" Local $strQuery = $strBase & ";" & $strFilter & ";" & $strAttributes & ";subtree" $objCommand.CommandText = $strQuery $objCommand.Properties ("Page Size") = 100 $objCommand.Properties ("Timeout") = 30 $objCommand.Properties ("Cache Results") = False $ADS_SCOPE_SUBTREE = 2 $objCommand.Properties ("searchscope") = $ADS_SCOPE_SUBTREE Local $objRecordSet = $objCommand.Execute While Not $objRecordSet.EOF ;~ $strName = $objRecordSet.Fields ("sAMAccountName").Value ;~ $strCN = $objRecordSet.Fields ("cn").value ;~ $strdisplayName = $objRecordSet.Fields ("displayName").value ;~ $strSN = $objRecordSet.Fields ("SN").value ;~ $strdistinguishedName = $objRecordSet.Fields ("distinguishedName").value ;~ $strSID = $objRecordSet.Fields ("distinguishedName").value FileWriteLine("Users.txt",$objRecordSet.Fields ("sAMAccountName").Value) $objRecordSet.MoveNext WEnd $objConnection.Close $objConnection = "" $objCommand = "" $objRecordSet = "" EndFunc ;==>_EnumUsers SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Ghost21 Posted May 21, 2008 Author Posted May 21, 2008 Something like this should work. You need to add the fields you require but it gets you started.JosFunc _EnumUsers() Local $objCommand = ObjCreate("ADODB.Command") Local $objConnection = ObjCreate("ADODB.Connection") $objConnection.Provider = "ADsDSOObject" $objConnection.Open ("Active Directory Provider") $objCommand.ActiveConnection = $objConnection Local $strBase = "<GC://dc=MyDom,dc=Inc>" Local $strFilter = "(&(objectCategory=person)(objectClass=user)(sAMAccountName=*))" Local $strAttributes = "cn,sAMAccountName,displayName,sn,distinguishedName" Local $strQuery = $strBase & ";" & $strFilter & ";" & $strAttributes & ";subtree" $objCommand.CommandText = $strQuery $objCommand.Properties ("Page Size") = 100 $objCommand.Properties ("Timeout") = 30 $objCommand.Properties ("Cache Results") = False $ADS_SCOPE_SUBTREE = 2 $objCommand.Properties ("searchscope") = $ADS_SCOPE_SUBTREE Local $objRecordSet = $objCommand.Execute While Not $objRecordSet.EOF ;~ $strName = $objRecordSet.Fields ("sAMAccountName").Value ;~ $strCN = $objRecordSet.Fields ("cn").value ;~ $strdisplayName = $objRecordSet.Fields ("displayName").value ;~ $strSN = $objRecordSet.Fields ("SN").value ;~ $strdistinguishedName = $objRecordSet.Fields ("distinguishedName").value ;~ $strSID = $objRecordSet.Fields ("distinguishedName").value FileWriteLine("Users.txt",$objRecordSet.Fields ("sAMAccountName").Value) $objRecordSet.MoveNext WEnd $objConnection.Close $objConnection = "" $objCommand = "" $objRecordSet = "" EndFunc ;==>_EnumUsers16) : ==> The requested action with this object has failed.: Local $objRecordSet = $objCommand.Execute Local $objRecordSet = $objCommand.Execute^ ERROR
Developers Jos Posted May 21, 2008 Developers Posted May 21, 2008 (edited) I guess you are asking if we can help you? Add the comerror handler as described in the helpfile to get the "real" error description. Edited May 21, 2008 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Ghost21 Posted May 21, 2008 Author Posted May 21, 2008 I guess you are asking if we can help you?Add the comerror handler as described in the helpfile to get the "real" error description.JoS: All I would like is a basic script to connect to AD and list PCs with names and other info .. I'm not trying to bve short with you.. I'm unsure how to work with com error handling .Thanks again
Developers Jos Posted May 21, 2008 Developers Posted May 21, 2008 (edited) JoS: All I would like is a basic script to connect to AD and list PCs with names and other info .. I'm not trying to bve short with you.. I'm unsure how to work with com error handling .Thanks againI am not trying to make your live difficult either but it has been a little like pulling teeth trying to help you and I also think people should do a part themselves to ensure they know what they are doing. The ComErrorEvent handler is described in the helpfile so I am not going to work it out for you.By the way:The script I gave is from a working script but I just removed the AD name and retrieves all USer objects from the AD and dumps them into a csv file.Jos Edited May 21, 2008 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now