antmar904 Posted January 15, 2019 Posted January 15, 2019 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 JLogan3o13 Posted January 15, 2019 Moderators Posted January 15, 2019 Look at the $Name array, is it returning what you expect it to? "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!
antmar904 Posted January 15, 2019 Author Posted January 15, 2019 32 minutes ago, JLogan3o13 said: Look at the $Name array, is it returning what you expect it to? No it is not...
Moderators JLogan3o13 Posted January 15, 2019 Moderators Posted January 15, 2019 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!
antmar904 Posted January 15, 2019 Author Posted January 15, 2019 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
antmar904 Posted January 15, 2019 Author Posted January 15, 2019 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()
Subz Posted January 15, 2019 Posted January 15, 2019 (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 January 15, 2019 by Subz
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now