Jump to content
Sign in to follow this  
hemichallenger

Active Directory _AD_GetObjectProperties

Recommended Posts

hemichallenger

Func _AD()
    _AD_Open()
    If $strAccount = Null Then
        MsgBox(16, "NULL", "No user currently logged on." )
    ElseIf _AD_ObjectExists(StringSplit($strAccount, '\', $STR_ENTIRESPLIT)[2]) Then
    $aProperties = _AD_GetObjectProperties(StringSplit($strAccount, '\', $STR_ENTIRESPLIT)[2], "lastLogon,telephoneNumber")
    GUICtrlSetData($Output, "Username : "& StringSplit($strAccount, '\', $STR_ENTIRESPLIT)[2] & @CRLF & _
    "Last Logon Time : "& $aProperties[1][1]& @CRLF & _
    "Telephone number : "& $aProperties[2][1])
    _AD_Close()
    Else
    GUICtrlSetData($Output, "Username : "& StringSplit($strAccount, '\', $STR_ENTIRESPLIT)[2] & @CRLF & _
    "Account name " & StringSplit($strAccount, '\', $STR_ENTIRESPLIT)[2] & " not in AD")
    EndIf
EndFunc

Maybe someone could point me in the right direction in how to fix this issue. Just having issues with accounts that have empty fields in AD like for example telephoneNumber. "Telephone number : "& $aProperties[2][1]) since im pulling information and the information aint there the script crashes. Is it possible if that field is empty to ignore that line?

Share this post


Link to post
Share on other sites
javiwhite

What's the error you're receiving? I'm assuming that its the array or subscript out of range error?

If that is the case, Just nest the GUIctrlSetData in an If Statement:

if uBound($aProperties,1) >= 3 then
GUICtrlSetData($Output, "Username : "& StringSplit($strAccount, '\', $STR_ENTIRESPLIT)[2] & @CRLF & _
    "Last Logon Time : "& $aProperties[1][1]& @CRLF & _
    "Telephone number : "& $aProperties[2][1])
endif

Obviously you'll need to play around with the numbers to suit your script; But from what you've provided; The above should be skipped if $aProperties[2][$x] dimension is out of range, and therefore suppress the error.

EDIT:

Apologies, On hindsight I've realised you probably don't want to skip all the information, Just the telephone.... In that case:

if uBound($aProperties,1) >= 3 then
     GUICtrlSetData($Output, "Username : "& StringSplit($strAccount, '\', $STR_ENTIRESPLIT)[2] & @CRLF & _
    "Last Logon Time : "& $aProperties[1][1]& @CRLF & _
    "Telephone number : "& $aProperties[2][1])
else
     GUICtrlSetData($Output, "Username : "& StringSplit($strAccount, '\', $STR_ENTIRESPLIT)[2] & @CRLF & _
    "Last Logon Time : "& $aProperties[1][1])
endif
Edited by javiwhite

give a man an application, and he'll be frustrated for the day, Teach him how to program applications and he'll be frustrated for a lifetime.

Share this post


Link to post
Share on other sites
water

What is the return value of _AD_GetObjectProperties and what is the value of @error and @extended?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - 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
hemichallenger

Func _AD()
    Local $strComputer = GUICtrlRead ($Input1)
    _AD_Open()
        If $strAccount = Null Then
    GUICtrlSetData($Output, "No user currently logged on to " & @CRLF & _
        $strComputer & ".")
       ElseIf _AD_ObjectExists(StringSplit($strAccount, '\', $STR_ENTIRESPLIT)[2]) Then
    $adObj_telephoneNumber = _AD_GetObjectProperties(StringSplit($strAccount, '\', $STR_ENTIRESPLIT)[2], 'telephoneNumber')
       If $adObj_telephoneNumber[0][0] <> 0 Then $adObj_telephoneNumber = $adObj_telephoneNumber[1][1]
    $adObj_LastLogon = _AD_GetObjectProperties(StringSplit($strAccount, '\', $STR_ENTIRESPLIT)[2], 'lastLogon')
       If $adObj_LastLogon[0][0] <> 0 Then $adObj_LastLogon = $adObj_LastLogon[1][1]
    GUICtrlSetData($Output, "Username : "& StringSplit($strAccount, '\', $STR_ENTIRESPLIT)[2] & @CRLF & _
    "Last Logon Time : "& $adObj_LastLogon & @CRLF & _
    "Telephone number : "& $adObj_telephoneNumber)
    _AD_Close()
      Else
    GUICtrlSetData($Output, "Username : "& StringSplit($strAccount, '\', $STR_ENTIRESPLIT)[2] & @CRLF & _
    "Account name " & StringSplit($strAccount, '\', $STR_ENTIRESPLIT)[2] & " does not exist in AD.")
    EndIf
EndFunc

I got it to work. Thanks guys for replying,

Share this post


Link to post
Share on other sites
water
:)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - 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  

  • Similar Content

    • Trinnon
      By Trinnon
      I have a question about the @error logging features in _AD_CreateUser.  Hopefully I am just missing something obvious.
      In my app I am creating a user if it does not exist then manipulating some attributes. 
      If the user does exist I would then call another function to remove groups from the user and modify some attributes.
      My question is...
      If the user already Exists, the _AD_CreateUser option gives $iValue = 0 and @error = 0.
      How can @error = 1 for the condition that the user already exists?
       
      I copied a small ship of the code in question along with my full .au3. 
      I am using AD UDF 1.4.9.0 (Water, thanks for the awesome work on this!!!).
      $iValue = _AD_CreateUser ($sOU, $sUser, $sCN)
      If $iValue = 1 Then
            _FileWriteLog ($Log, "Func UserCheck() - User '" & $sUser & "' successfully created ==> Calling UserAttribsNewUser Function.")
            Call ("NewUser")
      ElseIf @error = 1 Then
            _FileWriteLog ($Log, $sUser & " already exists ==> Calling UserAttribsExistingUser Function.")
            Call ("ExistingUser")
       
      AccountSettingConfigurations-Test1.au3
       
    • water
      By water
      Extensive library to control and manipulate Microsoft Active Directory.

      Threads: Development - General Help & Support - Example Scripts - Wiki
      Previous downloads: 30467
       
      Known Bugs: (last changed: 2018-06-01)
      None  
      Things to come: (last changed: 2018-06-01)
      None
      BTW: If you like this UDF please click the "I like this" button. This tells me where to next put my development effort
    • water
      By water
      ADAT is a tool to simplify common AD administration tasks. Every administration task has its own tab. It is easy to add new functions (tabs) to the tool. Some often used functions are already available: list users, computers, OUs. File ADAT.ini can be customized to hold the AD logon information if necessary.
      Known Bugs:
      2018-03-07: If the Script started from SciTE works but the "Process" button in the compiled exe does not do anything then please add the following line at the top of your script:
      #Au3Stripper_Ignore_Funcs=Process_Tab*
        BTW: If you like this tool please click the "I like this" button. This tells me where to next put my development effort
    • bouzzi
      By bouzzi
      Hi guys,
      I'm trying to make a script that could tell me, from a username list file,  if the username is active, inactive or not existant  in a multi-domain Active Directory....
      I found a few scripts giving me hints but I found nothing to help me to accomplish this task...
      Do you have any ideas !
      Thanks
      Bouzzi!
       
    • water
      By water
      On one/multiple big sheet(s) you get users (columns) and groups (rows). The list is sorted descending by number of members so you get the users with most groups and the groups with most members on top of the page. You can filter by (multiple) samaccountname(s), department or you can create your own LDAP query filter. You can filter the resulting list of groups using a Regular Expression.
      Version 2.0 uses maps so at the moment it requires the latest beta version of AutoIt!
      BTW: If you like this tool please click the "I like this" button. This tells me where to next put my development effort
×