• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 312
  • Last Modified:

Scripting to email me reports automatically

Good afternoon experts,

I have a number of servers which I generate reports to and at present have to log on to each server individually and things are a bit slow and cumbersome I have been looking at some scripts and log parser and just recently come across a program called Win Audit which looks like might be just the ticket.

What I want to be able to do is have a little script or batch file which is run automatically say Monday morning which runs the program from the command line with the right report content and then emails me the results when it is complete.  The servers which I do reports from all have Exchange.

The help files for Winaudit can be found at http://www.pxserver.com/WinAudit/hlp_command_line.html.  I have written wsh and vbscript before but struggling finding useful code which makes it easy to send an email and attach a file.  I would still like to look at using Log Parser because I have written some XML which ties in with eventid.net for each error code - but once I have the right code it should be a simple matter to adapt the script to work with that.

There are some other features ideas I have for down the road but initially start simple and get that working well

I look forward to hearing your responses

Paul

 
0
pcowen
Asked:
pcowen
  • 3
  • 2
1 Solution
 
mdiglioCommented:
Hello,
This might work for you
copy and paste this into notepad and save it with a .vbs extension

'Begin Copy
Set objEmail = CreateObject("CDO.Message")

objEmail.From = "yourEmail"
objEmail.To = "YourT0EmailAddress"
objEmail.Subject = "Subject Goes here""
objEmail.Textbody = "Message goes here"
objEmail.addAttachment ("C:/file.txt")

'These 4 objEmail.Configuration may not be necessary
'Make sure you change the smtp server string

    objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "your.smtp.server"

objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

objEmail.Configuration.Fields.Update

objEmail.Send
'End Copy
0
 
pcowenAuthor Commented:
Thanks I'll give that a whirl tomorrow.   If I want to run the command from the same script how is it best to do that with a vbscript

e.g. command to be run from command line is c:\winaudit\winaudit /r=ed /o=PDF

something like
Dim objShell.objExec
Set objShell=CreateObject("wscript.shell")
strCommand ="cmd c:\winaudit\winaudit /r=ed /o=PDF"

Set objExec=objShell.Exec(strCommand)

Am I likely to need some sort of wait command also before trying to email the file?

Thanks

Paul
0
 
mdiglioCommented:
Yes you probably will need the wait command
Run some tests and find out how long you will need to wait.

Your finished script will be:
What you just posted
then
wscript.sleep 9000
then the script I posted


wscript.sleep is what you will use to make the script pause
1000 = 1 second
0
 
pcowenAuthor Commented:
Thanks - am trying to get it working - think it needs playing around with this line:

objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "your.smtp.server"

Where would be the best place for me to look this up?

P
0
 
mdiglioCommented:
Do you mean look up what your smtp server is?
If yes, you can find that in your email client
If you have Outlook then the steps are:
Open Outlook >  tools > email accounts > view or change existing email accounts > click change > look for smtp tab

You could try the script without these 4 lines and it might work:

   objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "your.smtp.server"

objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

objEmail.Configuration.Fields.Update
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.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now