Schedule a weekly report of expiring accounts in Active Directory?

We have accounts which are set to expire on a certain date. We would like to receive a report every week of accounts with expiration dates. i imagine creating a script which picks up a txt file and emails it to me is fairly easy and i can put that into a scheduled task. what i need help with is creating a script which creates the txt file. Ideally the script would query AD for any accounts with "account expires" set to a specific date and list only those accounts in the file. Note that I am not referring to password expiration here but account expiration.
hartwellcorpAsked:
Who is Participating?
 
AmitConnect With a Mentor IT ArchitectCommented:
1) Create one folder in c: drive name it like : acctexp
2) Then copy that .exe into this folder
3) create a batch file accexp.bat, open it with the notepad and put the command which you gave it to extract txt file. Example: FindExpAcc >> result.txt
4) create new notepad file and paste below code and save it as send.vbs you need to edit some sections like filepath, SMTP Server Name, To and From Email ID
      
      'WScript.Echo "in send mail function"
      
      Set iMsg = CreateObject("CDO.Message")
      Set iConf = CreateObject("CDO.Configuration")
      Set Flds = iConf.Fields
      
      filepath="C:\acctexp\result.txt"
      
            
      With Flds
            .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
            'ToDo: Enter name or IP address of remote SMTP server.
            .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "SMTP Server name"
            .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
            .Update
      End With
      
      ' Apply the settings to the message.
      With iMsg
            Set .Configuration = iConf
            .To = "youremailid@yourdomain.com"  'ToDo: Enter a valid email address.
            .From = "youremailid@yourdomain.com"  'ToDo: Enter a valid email address.
            .TextBody = "AcctExp Report"
            .Subject = "AcctExp Report"
            .AddAttachment filepath
            .Send
      End With
      
      'WScript.echo "Sending EMail to AcctExp team..!!"

5)Next create one more batch file send.bat and paste below lines
c:\acctexp\send.vbs
FindExpAcc > result.txt 'This will overwrite the old file, this is optional'
6) Now open schedule task and create a task, browse to send.bat and schedule it accordingly, how frequent you want to do it. Every 15mins or a day etc.

Hope this helps.
0
 
AmitIT ArchitectCommented:
You can use this free tool
http://www.joeware.net/freetools/tools/findexpacc/index.htm

Also you can batch it and export the result to a text file and email it via script.
0
 
hartwellcorpAuthor Commented:
Thank you for find that for me. I'll check it out.
0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

 
hartwellcorpAuthor Commented:
so that does save exactly what i want to a txt file. you mention "email it via script". do you have an example of how one does that?
0
 
hartwellcorpAuthor Commented:
I am trying that now. is there a way i can instead send the contents of the txt file in the body of the message? that way we dont even have to open an attachment?
0
 
hartwellcorpAuthor Commented:
maybe this tool wont work. the format of the output is a mess. unless you know a way around this?


DN,cn,displayName,sAMAccountName,accountExpires,expireDays,mail
"cn=marks,ou=visitors,ou=hartwellusers,dc=hartwellcorp,dc=com","marks","Mark Stuvetraa","marks","2012/03/11-00:00:00","67",""
"cn=epitech,ou=visitors,ou=hartwellusers,dc=hartwellcorp,dc=com","epitech","Epicor Tech Support VPN account","epitech","2012/02/01-00:00:00","28",""
"cn=jimh,ou=visitors,ou=hartwellusers,dc=hartwellcorp,dc=com","jimh","Jim Howell","jimh","2011/08/31-23:00:00","-124",""
"cn=jeffz,ou=visitors,ou=hartwellusers,dc=hartwellcorp,dc=com","jeffz","Jeff Zonick","jeffz","2010/07/31-23:00:00","-520",""
"cn=michaels,ou=visitors,ou=hartwellusers,dc=hartwellcorp,dc=com","michaels","Michael Serrato","michaels","2011/01/01-00:00:00","-367",""
"cn=shorwitz,ou=visitors,ou=hartwellusers,dc=hartwellcorp,dc=com","shorwitz","Steve Horwitz","shorwitz","2012/01/13-00:00:00","9",""
"cn=dhaynes,ou=visitors,ou=hartwellusers,dc=hartwellcorp,dc=com","dhaynes","David Haynes","dhaynes","2012/01/12-00:00:00","8",""
"cn=rodb,ou=visitors,ou=hartwellusers,dc=hartwellcorp,dc=com","rodb","Rod Biagtan","rodb","2012/02/02-00:00:00","29","rodb@Hartwellcorp.com"
"cn=susanj,ou=visitors,ou=hartwellusers,dc=hartwellcorp,dc=com","susanj","Susan Joslyn","susanj","2012/01/11-00:00:00","7","susanj@Hartwellcorp.com"
"cn=dtl,ou=visitors,ou=hartwellusers,dc=hartwellcorp,dc=com","dtl","DTL Consultant","dtl","2012/02/02-00:00:00","29",""
0
 
hartwellcorpAuthor Commented:
by the way, all of your suggestions so far have worked. i now have a task scheduled that runs fine and it refreshes the output file and then sends it to me in an email. I just really need to clean up the output as it is quite difficult to read. thanks!!
0
 
hartwellcorpAuthor Commented:
Thank you!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.