I'm rebuilding my PowerShell script with Python. Sole purpose of that is to easily insert data to Postgre DB tables with Python. PowerShell script works as it should, but when it comes to Python I encountered a obstacle.
In this loop, I gather all data - most like direct reports from specific AD account. As you may see, I already gather account name, name/surname, e-mail address and password last set date. The problem is to calculate password age. In PS it was pretty easy, but when I ran a code in Python, I get an Exception has occurred: TypeError can't subtract offset-naive and offset-aware datetimes
Here is the part of the code:
reports = getDirectReports(managers_name)
for users in reports:
for user in users.directReports.values:
if 'cn=ext.' in user.lower():
user_details = getUserDetails(user)
print(user_details[0].cn.value)
print(user_details[0].givenName.value)
print(user_details[0].sn.value)
print(user_details[0].pwdLastSet.value)
print(user_details[0].mail.value)
current_date = datetime.now()
start_date = user_details[0].pwdLastSet.value
if (start_date == 0):
password_age = 'NULL'
else:
password_age = current_date - start_date ```