Sign in to follow this  
Followers 0
JamesDover

Pull Phone Numbers From Active Directory

16 posts in this topic

I found the adfunctions.au3 but was unable to find information on how to pull certin things from active directory. Could someone link or help me find some more information on this?

Cheers

Share this post


Link to post
Share on other sites



You could use my Active Directory UDF (ad.au3) which is the successor of adfunctions.au3 (for download please see my signature).

Which function to use depends on what you want to do.

A good place to start is function _AD_GetObjectsInOU. Please have a look at the example script file _AD_GetObjectsInOU.au3.

The phone number is just a property of an user object. Do you want just a single user or a (filtered) list of users?


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

#3 ·  Posted (edited)

Excellent just what I was looking for.

Danke

You could use my Active Directory UDF (ad.au3) which is the successor of adfunctions.au3 (for download please see my signature).

Which function to use depends on what you want to do.

A good place to start is function _AD_GetObjectsInOU. Please have a look at the example script file _AD_GetObjectsInOU.au3.

The phone number is just a property of an user object. Do you want just a single user or a (filtered) list of users?

Edited by JamesDover

Share this post


Link to post
Share on other sites
:mellow:

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

#5 ·  Posted (edited)

One more quick question with the _AD_GetObjectsInOU if i decide to make the output ($output to display on a form) instead of _ArrayDisplay would this be possible? Also I can't seem to get the lastLogon (date) to show up in the array i must be doing something wrong.

#AutoIt3Wrapper_AU3Check_Parameters= -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=Y
#include <AD.au3>

_AD_Open()
Global $sOU = "OU=LUsers,OU=Users,OU=test,DC=test1,DC=edu" ;
Global $aObjects[1][1]
$aObjects = _AD_GetObjectsInOU($sOU, "(sAMAccountName=Sam.Turner)", 2, "Telephone number,lastLogon") 
If @error > 0 Then
    MsgBox(64, "Active Directory Functions", "No OUs could be found")
Else
    _ArrayDisplay($aObjects, "Missing E-Mail and Phone Numbers '" & $sOU & "'")
EndIf
_AD_Close()

Cheers

:mellow:

Edited by JamesDover

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

One more quick question with the _AD_GetObjectsInOU if i decide to make the output ($output to display on a form) instead of _ArrayDisplay would this be possible?

How you display the data returned by a functions is up to you. _AD_GetObjectsInOU simply returns an array.

Also I can't seem to get the lastLogon (date) to show up in the array i must be doing something wrong.

Active Directory stores different types of data (strings, arrays, data that needs some sort of "interpretation", data that needs to be accessed in a special way).

Function _AD_GetObjectsInOU returns the data "as is" - so it's only useful for string and array type of data.

To get "interpreted" data you could use _AD_GetObjectProperties. This function translates all kind of data into readable form.

To get the LastLogon data you need to use function _AD_GetLastLoginDate. The data is stored on the domain controller where the user logged on and isn't replicated to other domain controllers. This is why function _AD_GetLastLoginDate queries all DC to return the correct data.

_AD_GetObjectsInOU is best to be used when a lot of recordes will be returned e.g. give me all users with department = xy

_AD_GetObjectProperties is best to be used when you need to query all/some properties of a single object (user, computer, group) and need the data in readable form.

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

Ad.au3 has a lot of good uses I wish I found it long ago. Hopefully they will add it to the auto-it include folder in future releases. Your information is very helpful as always.

Cheers

How you display the data returned by a functions is up to you. _AD_GetObjectsInOU simply returns an array.

Active Directory stores different types of data (strings, arrays, data that needs some sort of "interpretation", data that needs to be accessed in a special way).

Function _AD_GetObjectsInOU returns the data "as is" - so it's only useful for string and array type of data.

To get "interpreted" data you could use _AD_GetObjectProperties. This function translates all kind of data into readable form.

To get the LastLogon data you need to use function _AD_GetLastLoginDate. The data is stored on the domain controller where the user logged on and isn't replicated to other domain controllers. This is why function _AD_GetLastLoginDate queries all DC to return the correct data.

_AD_GetObjectsInOU is best to be used when a lot of recordes will be returned e.g. give me all users with department = xy

_AD_GetObjectProperties is best to be used when you need to query all/some properties of a single object (user, computer, group) and need the data in readable form.

Share this post


Link to post
Share on other sites

Glad you like the UDF.

If you want to show other users how useful the UDF is you can go to the download page and click on one of the stars at "Rate topic:"


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

I guess it would work like this after creating a forum?

Thanks

#AutoIt3Wrapper_AU3Check_Parameters= -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

#AutoIt3Wrapper_AU3Check_Stop_OnWarning=Y

#include <AD.au3>

; Open Connection to the Active Directory

_AD_Open()

Global $aProperties[1][2];<----------- How do these numbers work?

$aProperties = _AD_GetObjectProperties("John.Jones", "Telephone number")

;_ArrayDisplay($aProperties, "Telephone Number")

GUICtrlSetData($PhoneNumberInput, $aProperties);<--------------------------- Is this possible?

_AD_Close()

Share this post


Link to post
Share on other sites

Global $aProperties[1][2];<----------- How do these numbers work?

This declares a new array with 2 dimensions. First dimension has 1 Element and second dimension 2 elements.

Effectively you can use $aProperties[0][0] and $aProperties[0][1]

GUICtrlSetData($PhoneNumberInput, $aProperties);<--------------------------- Is this possible?

No, see description above. Try:

GUICtrlSetData($PhoneNumberInput, $aProperties[0][1])

$aProperties[0][1] is just a guess. :mellow:


Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites

Do you need something like this :mellow:

#include <ad.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $sUserName

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 332, 146, 192, 124)
GUICtrlCreateLabel("Please enter User Name:", 16, 18, 122, 17)
GUICtrlCreateLabel("Telephone number:", 16, 52, 96, 17)
$IUserName = GUICtrlCreateInput("", 153, 16, 159, 21)
$IPhoneNumber = GUICtrlCreateInput("", 152, 50, 159, 21, BitOR($ES_AUTOHSCROLL,$ES_READONLY))
$BtnExit = GUICtrlCreateButton("Exit", 248, 96, 65, 33, $WS_GROUP)
$BtnGo = GUICtrlCreateButton("Go", 16, 96, 65, 33, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

_AD_Open()
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $BtnExit
            _AD_Close()
            Exit
        Case $BtnGo
            $sUser = GUICtrlRead($IUserName)
            If $sUser <> "" Then
                $sPhoneNumber = _AD_GetObjectAttribute($sUser, "telephonenumber")
                GUICtrlSetData($IPhoneNumber, $sPhoneNumber)
            Endif
    EndSwitch
WEnd

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

#12 ·  Posted (edited)

Cheers, I was stuck on the purpose of the numbers.

Water, yes that is what i was looking for :mellow:

This declares a new array with 2 dimensions. First dimension has 1 Element and second dimension 2 elements.

Effectively you can use $aProperties[0][0] and $aProperties[0][1]

No, see description above. Try:

GUICtrlSetData($PhoneNumberInput, $aProperties[0][1])

$aProperties[0][1] is just a guess. :)

Edited by JamesDover

Share this post


Link to post
Share on other sites

I am using _AD_GetObjectsInOU to retrive the name,operatingsystem and service pack. The problem is the server is windows 2000. Has any one had any luck with windows 2000 I can't seem to make it work. It could be my $sOU is wrong.

Cheers

#include <AD.au3>
_AD_Open()
Global $sOU = "OU=Computers,DC=MyZone,DC=local"
Global $aObjects[1][1]
$aObjects = _AD_GetObjectsInOU($sOU, "(name=*)", 2, "sAMAccountName,operatingSystem,operatingSystemServicePack") ;Workstations
If @error > 0 Then
MsgBox(64, "Active Directory", "No OUs could be found")
Else
_ArrayDisplay($aObjects, "Os And ServicePak" & $sOU & "'")
EndIf
_AD_Close()

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Could you please try this modified code? This LDAP query only returns computer objects.

#include <AD.au3>
_AD_Open()
Global $sOU = "OU=Computers,DC=MyZone,DC=local"
Global $aObjects[1][1]
$aObjects = _AD_GetObjectsInOU($sOU, "(objectClass=computer)", 2, "sAMAccountName,operatingSystem,operatingSystemServicePack") ;Workstations
If @error > 0 Then
MsgBox(64, "Active Directory", "No OUs could be found")
Else
_ArrayDisplay($aObjects, "Os And ServicePak" & $sOU & "'")
EndIf
_AD_Close()
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

I recived this error. :graduated:

Posted Image

Share this post


Link to post
Share on other sites

The image can not be displayed. Can you post the error as text?


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