Jump to content
Sign in to follow this  
Praxi

_ADGETOBJECTSINOU and adfunctions.au3

Recommended Posts

Praxi

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

Share this post


Link to post
Share on other sites
PsaltyDS

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

Share this post


Link to post
Share on other sites
Praxi

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.RecordCount

I 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

:)

Share this post


Link to post
Share on other sites
Praxi

Any other hints as to why it would be generating a com error?

Share this post


Link to post
Share on other sites
PsaltyDS

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

Share this post


Link to post
Share on other sites
Praxi

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.

Share this post


Link to post
Share on other sites
Praxi

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.

Share this post


Link to post
Share on other sites
PsaltyDS

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 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

Share this post


Link to post
Share on other sites
Jeannot

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 :P

Ps : Even how to filter enabled/disabled accounts

Edited by Jeannot

Share this post


Link to post
Share on other sites
water

Please check out this post (it's mine :P) - there you'll find a link to a site with many examples for LDAP queries.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

De rien :P


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.