Jump to content

Recommended Posts

Posted

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?

Posted (edited)

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.

Posted

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

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

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,

Posted
:)

My UDFs and Tutorials:

  Reveal hidden contents

 

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
×
×
  • Create New...