Jump to content

How do I add content to a ComboBox from an AD attribute?


Valnurat
 Share

Recommended Posts

Hi.

Can someone help me with some code to get info from AD and into a ComboBox. I'm using this UDF:

How do you get AD user object with the StaffManager attributes = True? I think I have to use:

_AD_GetObjectsInOU($sOU[, $sFilter = "(name=*)"[, $iSearchScope = 2[, $sDataToRetrieve =  "sAMAccountName"[, $sSortBy = "sAMAccountName"[, $bCount = False[, $vReturnNull = True]]]]])

but I don't know how.

 

Yours sincerely

Kenneth.

Link to comment
Share on other sites

Something like (untested):

$aObjects = _AD_GetObjectsInOU("", "(&(objectcategory=person)(objectclass=user)(StaffManager=True))", 2, "sAMAccountName,distinguishedName,displayname", "displayname")

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <AD.au3>
#include <Array.au3>

Main()

Func Main()
    _AD_Open()
    ; Create a GUI with various controls.
    Local $hGUI = GUICreate("Example")
    GUICtrlCreateCombo("Sample Combo", 250, 80, 120, 100)
    $aObject = _AD_GetObjectsInOU("","(&(objectclass=person)(StaffManager=True))",2,"sAMAccountName,distinguishedName,displayname", "displayname")
    _ArrayDisplay($aObject,"")

    Local $idOK = GUICtrlCreateButton("OK", 310, 370, 85, 25)
    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)
    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idOK
                MsgBox($MB_SYSTEMMODAL, "", "test")
        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
    _AD_Close()
EndFunc

I tried this, but I don't get anything in the _arrayDisplay.

 

SOLVED: I need to use big letters in the "True". Like this "TRUE"

Edited by Valnurat
SOLVED

Yours sincerely

Kenneth.

Link to comment
Share on other sites

What's the value of @error and @extended after _AD_GetObjectsInOU?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

Use GUICtrlSetData as seen in the example for GUICtrlCreateCombo.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

I've looked at GUICtrlSetData and I understand that input should be with the pipe character (|) as separator.

In the _AD_GetObjectsInOU remarks it says "Multi-value attributes are returned as a string with the pipe character (|) as separator".

So why does GUICtrlSetData not work?
 

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=x86\Create Consultant.Exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <AD.au3>
#include <Array.au3>

Main()

Func Main()
    _AD_Open()
    ; Create a GUI with various controls.
    Local $hGUI = GUICreate("Example")
    Local $idComboBox = GUICtrlCreateCombo("Sample Combo", 250, 80, 120, 100)
    local $aObject = _AD_GetObjectsInOU("OU=Users,OU=so,OU=dk,OU=company,DC=AD,DC=company,DC=ORG","(&(objectclass=person)(StaffManager=TRUE))",2,"sAMAccountName,distinguishedName,displayname", "displayname")
    ; Add additional items to the combobox.
    GUICtrlSetData($idComboBox, $aObject, "")

    Local $idOK = GUICtrlCreateButton("OK", 310, 370, 85, 25)
    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)
    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idOK
                MsgBox($MB_SYSTEMMODAL, "", "test")
        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
    _AD_Close()
EndFunc

Is the _AD_GetObjectsInOU not separated with a pipe in this case?

Yours sincerely

Kenneth.

Link to comment
Share on other sites

It depends:

  • When a single attribute contains multiple values then you get a single entry in the array where the values are separated by the pipe character
  • When there are multiple attributes you get multiple entries in the returned array with the same attribute name

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
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
 Share

×
×
  • Create New...