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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

AmitIT 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Active Directory

From novice to tech pro — start learning today.