@@ -844,10 +844,15 @@ def active_users(self):
844844 argsusers = allusers
845845
846846 for user in allusers :
847- account_disabled = int (user .get ("userAccountControl" )) & 2
848- if not account_disabled :
849- count += 1
850- activeusers .append (user .get ("sAMAccountName" ).lower ())
847+ user_account_control = user .get ("userAccountControl" )
848+ if user_account_control is not None : # Check if user_account_control is not None
849+ account_control = "" .join (user_account_control ) if isinstance (user_account_control , list ) else user_account_control # If it's already a list
850+ account_disabled = int (account_control ) & 2
851+ if not account_disabled :
852+ count += 1
853+ activeusers .append (user .get ("sAMAccountName" ).lower ())
854+ else :
855+ self .logger .debug (f"userAccountControl for user { user .get ('sAMAccountName' )} is None" )
851856
852857 if self .username == "" :
853858 self .logger .display (f"Total records returned: { len (resp ):d} " )
@@ -856,15 +861,17 @@ def active_users(self):
856861 continue
857862 self .logger .highlight (f"{ item ['objectName' ]} " )
858863 return
859- self .logger .display (f"Total records returned: { len ( allusers ) } , Total { len (allusers ) - count :d} user(s) disabled" ) if not arg else self .logger .display (f"Total records returned: { len (argsusers )} , Total { len (allusers ) - count :d} user(s) disabled" )
864+ self .logger .display (f"Total records returned: { count } , total { len (allusers ) - count :d} user(s) disabled" ) if not arg else self .logger .display (f"Total records returned: { len (argsusers )} , Total { len (allusers ) - count :d} user(s) disabled" )
860865 self .logger .highlight (f"{ '-Username-' :<30} { '-Last PW Set-' :<20} { '-BadPW-' :<8} { '-Description-' :<60} " )
861866
862867 for arguser in argsusers :
863- timestamp_seconds = int (arguser .get ("pwdLastSet" , "" )) / 10 ** 7
864- start_date = datetime (1601 , 1 , 1 )
865- parsed_pw_last_set = (start_date + timedelta (seconds = timestamp_seconds )).replace (microsecond = 0 ).strftime ("%Y-%m-%d %H:%M:%S" )
866- if parsed_pw_last_set == "1601-01-01 00:00:00" :
867- parsed_pw_last_set = "<never>"
868+ pwd_last_set = arguser .get ("pwdLastSet" , "" ) # Retrieves pwdLastSet directly and defaults to an empty string.
869+ if pwd_last_set : # Checks if pwdLastSet is empty or not.
870+ timestamp_seconds = int (pwd_last_set ) / 10 ** 7 # Converts pwdLastSet to an integer.
871+ start_date = datetime (1601 , 1 , 1 )
872+ parsed_pw_last_set = (start_date + timedelta (seconds = timestamp_seconds )).replace (microsecond = 0 ).strftime ("%Y-%m-%d %H:%M:%S" )
873+ if parsed_pw_last_set == "1601-01-01 00:00:00" :
874+ parsed_pw_last_set = "<never>"
868875
869876 if arguser .get ("sAMAccountName" ).lower () in activeusers and arg is False :
870877 self .logger .highlight (f"{ arguser .get ('sAMAccountName' , '' ):<30} { parsed_pw_last_set :<20} { arguser .get ('badPwdCount' , '' ):<8} { arguser .get ('description' , '' ):<60} " )
0 commit comments