?
Solved

Scripting to email me reports automatically

Posted on 2006-05-15
5
Medium Priority
?
303 Views
Last Modified: 2012-06-22
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
Comment
Question by:pcowen
  • 3
  • 2
5 Comments
 
LVL 16

Accepted Solution

by:
mdiglio earned 1600 total points
ID: 16685154
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
 

Author Comment

by:pcowen
ID: 16685412
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
 
LVL 16

Expert Comment

by:mdiglio
ID: 16685878
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
 

Author Comment

by:pcowen
ID: 16711260
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
 
LVL 16

Expert Comment

by:mdiglio
ID: 16711503
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Batuhan Cetin Within the dynamic life of an IT administrator, we hold many information in our minds like user names, passwords, IDs, phone numbers, incomes, service tags, bills and the order from our wives to buy milk when coming back to home.…
I guess it is not common knowledge to most Wintel engineers/administrators: If you have an SNMP-based monitoring system in your environment (and it's common to have SNMP or Syslog) it's reasonably easy to enable monitoring of the Windows Event logs,…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question