I am trying to create an email notification for users which have a password expiring soon. I then want to include the number of days until it expires.
I have the below search. It returns the users which are due to expire. It then emails every user which it returns which has an email address assigned to it in AD. I cannot seem to find a way to include how many days until it expires.
| ldapsearch domain=default search="(&(objectclass=user)(!(objectclass=computer)))" attrs="displayName, whenCreated, pwdLastSet, mail"
| dedup displayName
| eval DateLastChanged=strptime(pwdLastSet, "%Y-%m-%dT%H:%M:%S.%N")
| where DateLastChanged < relative_time(now(),"-69d@d")
| table DateLastChanged, displayName, mail
| outputcsv TempEmailFile.csv
| stats values(mail) AS email, values(DateLastChanged) as DateLastChanged
| mvexpand email
| map search="|inputcsv TempEmailFile.csv | where mail=\"$email$\"
| fields - mail
| sendemail
sendresults=false inline=true
server="0.0.0.0"
from="senderemail"
to=\"$email$\"
subject=\"Password Reminder\"
message=\"Your password is due to expire in ??? Days.\""
If anyone can think of a way to make it better to make it include the days until it expires, i would be very grateful
... View more