Praxi Posted May 21, 2008 Posted May 21, 2008 Hi all, I am trying to use adfunctions.au3 as a include and retrieve a list of users. My ultimate goal, I just need to check to see if they have an email address entered, and if not enter one from a CSV text file. I can deal with the text file just fine. But I'm having troubles getting _ADGETOBJECTSINOU to return an array. I have never really worked with arrays, and I'm not a programmer. I understand the idea of an array (god bless the autoit wiki) I'm just not sure how to handle it. Here is the code I have started so far. And every time I run it, my console reports that my $EXISTINGUSER is not an array. What am I doing wrong here (I'm sure theres lots of things ;============================================================================= ; Includes ;============================================================================= #include <Guiconstants.au3> #include <Constants.au3> #include <adfunctions.au3> #include <array.au3> ;============================================================================= ; GLOBAL VARIABLES ;============================================================================= Dim $object,$attribute="mail",$ou="ou=DesktopAdmins,DC=OED,DC=LOCAL",$OCLASS="(objectClass=user)" ;============================================================================= ; MAIN ;============================================================================= ;$userexists=Call(_ADObjectExists,$object) dim $EXISTINGUSER[50] $EXISTINGUSER=Call("_ADGetObjectsInOU",$ou) If IsArray($EXISTINGUSER) Then Local $iMax = UBound($EXISTINGUSER) ConsoleWrite("Items in the array: " & $iMax) For $i = 0 to $iMax - 1 ConsoleWrite($EXISTINGUSER[$i] & @LF) Next Else ConsoleWrite("Not an Array") EndIf
PsaltyDS Posted May 21, 2008 Posted May 21, 2008 Try it this way: #include <adfunctions.au3> Dim $ou = "ou=DesktopAdmins,DC=OED,DC=LOCAL" Dim $EXISTINGUSER _ADGetObjectsInOU($EXISTINGUSER, $ou) If IsArray($EXISTINGUSER) Then ConsoleWrite("Items in the array: " & UBound($EXISTINGUSER)) For $i = 0 To UBound($EXISTINGUSER) - 1 ConsoleWrite($EXISTINGUSER[$i] & @LF) Next Else ConsoleWrite("Not an Array") EndIf Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Praxi Posted May 21, 2008 Author Posted May 21, 2008 ahh, I don't have to do a call to _ADGETOBJECTSINOU? the UDF's (think I have the right term there) do that on their own?I tried that, and I generated a com error # 000000A9 on line 641 Windescription "Variable must be of type 'Object'". Looking on line 641 in adfunctions.au3 I see$recordcount = $objRecordSet.RecordCountI can sort of trace it back through the _ADGETOBJECTSINOU function, but I don't understand much of what its REALLY doing.Try it this way: #include <adfunctions.au3> Dim $ou = "ou=DesktopAdmins,DC=OED,DC=LOCAL" Dim $EXISTINGUSER _ADGetObjectsInOU($EXISTINGUSER, $ou) If IsArray($EXISTINGUSER) Then ConsoleWrite("Items in the array: " & UBound($EXISTINGUSER)) For $i = 0 To UBound($EXISTINGUSER) - 1 ConsoleWrite($EXISTINGUSER[$i] & @LF) Next Else ConsoleWrite("Not an Array") EndIf
Praxi Posted May 21, 2008 Author Posted May 21, 2008 Any other hints as to why it would be generating a com error?
PsaltyDS Posted May 22, 2008 Posted May 22, 2008 Any other hints as to why it would be generating a com error?Not from me. I'm not having any luck with adfunctions.au3, now that I've had a chance to try it with a Win2K3 domain. A valid OU string that works fine with other ADODB to AD stuff fails with this function. The .execute fails to return a record set object, which leads to the error message when you try to use the record set. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Praxi Posted May 22, 2008 Author Posted May 22, 2008 ahh thats too bad, I liked the idea of the adfunctions.au3. Guess I will search the forum for other example scripts to retrieve attributes of user objects.
Praxi Posted May 22, 2008 Author Posted May 22, 2008 doh I was running an old version. Used 3.0 from Johnny C's original post, not 3.1 from the downloads area. Works now, thanks for your help PSalty.
PsaltyDS Posted May 22, 2008 Posted May 22, 2008 (edited) doh I was running an old version. Used 3.0 from Johnny C's original post, not 3.1 from the downloads area. Works now, thanks for your help PSalty. Oh! Good call. I had the old version too. After a cursory look, the only difference I see between them is: $filter = "(name=*)" Vice $filter = "name='*'" But now it works. P.S. As of this post, the latest version of adfunctions.au3 is 3.1.2 dated October, 2007: ; Active Directory Function Library. Include this to allow access to Active Directory Functions ; Author : Jonthan Clelland ; Email : jclelland<at>statestreet<dot>com ; Version : 3.1.1 (sic, actual version is 3.1.2 according to changes below) ;Version History -- Starting from v3.1 ; 3.1 -- First released version ; 3.1.1 -- Bugfix to _ADGetObjectsInOU, default $filter value caused errors. Has been changed. ; 3.1.2 -- Corrections made to comments, replaced occurrences of 'Samaccountname' with 'Full Distringuished Name' where this had changed ibn the code. ; 3.1.2 -- Change to '_ADUserCreateMailbox', added '$emaildomain' and removed the hard-coded Email Domain name. Edited May 22, 2008 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Jeannot Posted March 3, 2009 Posted March 3, 2009 (edited) Hi everybody, I saw in _ADGetObjectsInOU that there is a sortby option but it seems to be not coded... I use _ArraySort() as fix #include <adfunctions.au3> Dim $ou = "ou=DesktopAdmins,DC=OED,DC=LOCAL" Dim $EXISTINGUSER _ADGetObjectsInOU($EXISTINGUSER, $ou, "(name=*)", 0, "sAMAccountName", "sAMAccountName") _ArraySort($EXISTINGUSER, 0, 1) If IsArray($EXISTINGUSER) Then ConsoleWrite("Items in the array: " & UBound($EXISTINGUSER)) For $i = 0 To UBound($EXISTINGUSER) - 1 ConsoleWrite($EXISTINGUSER[$i] & @LF) Next Else ConsoleWrite("Not an Array") EndIf Also, I need some help with filter syntax (to get only users and not computers account). I tried (class=user), but it doesn't work Ps : Even how to filter enabled/disabled accounts Edited March 3, 2009 by Jeannot
water Posted March 3, 2009 Posted March 3, 2009 (edited) Please check out this post (it's mine ) - there you'll find a link to a site with many examples for LDAP queries. Edited March 3, 2009 by water My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
water Posted March 3, 2009 Posted March 3, 2009 De rien My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
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