Jump to content

Recommended Posts

Posted

Hi,

I am trying to get a users AD attribute called "AccountExpirationDate" but I keep getting this error:

(21) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

 

#include <AD.au3>
#include <Array.au3>
#include <File.au3>
#include <AutoItConstants.au3>


; Open Connection to the Active Directory
_AD_Open()
If @error Then
    MsgBox(0, "", @error)
EndIf

$Users = FileReadToArray(@ScriptDir & "\UsersList.txt")

;_ArrayDisplay($Users)

;Get users "Name" attribute in AD
For $i = 0 To UBound($Users) - 1
    Local $Name = _AD_GetObjectProperties($Users[$i], "AccountExpirationDate")
    FileWriteLine(@ScriptDir & "\OutputFile.txt", $Users[$i] & " " & $Name[1][1])
Next

_AD_Close()

 

  • Moderators
Posted

Hence your issue. This works for me in my domain:

Local $Name = _AD_GetObjectProperties($Users[$i], "AccountExpires")

although we don't use that field so it comes up 0000/00/00 00:00:00

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Posted
1 hour ago, JLogan3o13 said:

Hence your issue. This works for me in my domain:

Local $Name = _AD_GetObjectProperties($Users[$i], "AccountExpires")

although we don't use that field so it comes up 0000/00/00 00:00:00

I was using the wrong attribute name :)

How check the accountexpire array and if it is set to not expire "0000/00/00 00:00:00" then write "Does not expire" in the text file?

If $Name[1][1] = "0000/00/00 00:00:00" Then

 

Posted

For some reason my script is stopping mid way and not running for all users in my list.

Error: Subscript used on non-accessible variable

#include <AD.au3>
#include <Array.au3>
#include <File.au3>
#include <AutoItConstants.au3>


; Open Connection to the Active Directory
_AD_Open()
If @error Then
    MsgBox(0, "", @error)
EndIf

$Users = FileReadToArray(@ScriptDir & "\UsersList.txt")

_ArrayDisplay($Users)

For $i = 0 To UBound($Users) - 1
    Local $Name = _AD_GetObjectProperties($Users[$i], "AccountExpires")
    ;_ArrayDisplay($Name)
    If $Name[1][1] = "1601/01/01 00:00:00" Then
        FileWriteLine(@ScriptDir & "\OutputFile.txt", $Users[$i] & " " & "DOES NOT EXPIRE")
    Else
        FileWriteLine(@ScriptDir & "\OutputFile.txt", $Users[$i] & " " & $Name[1][1])
    EndIf
Next

_AD_Close()

 

Posted (edited)

Use $Name[$i][1] otherwise you're only checking the first user over and over again.

Sorry just re-read the post, you need to use something like

Local $Name = _AD_GetObjectProperties($Users[$i], "AccountExpires")
    If @error Then Continueloop ;~ User was not found, see return values for _AD_GetObjectProperties()

 

Edited by Subz

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