email result of scheduled task

Hi  all  I've created a task to run repadmin.exe /replsummary. is it possible to email the the result.  Thanks
LVL 15
cwstad2Asked:
Who is Participating?
 
Raheman M. AbdulConnect With a Mentor Senior Infrastructure Support Analyst & Systems DeveloperCommented:
Try this:

$replsummary = invoke-expression { cmd.exe /c repadmin.exe /replsummary }
$Body = $replsummary

$to = "receivername@domain.com"
$from = "sendername@domain.com"
 Send-MailMessage -SmtpServer mail.domain.com -From $from  -To $to -Subject 'repl Summary' -Body $body
0
 
Santosh GuptaConnect With a Mentor Commented:
Hi,

if you are using windows 2008 or 2012 then you can achieve this goal by using the "Task Scheduler".
sch
1. create a task to run "repadmin.exe /replsummary > C:\reports\Replication_report.txt".
2. create another task to send the email with using "Replication_report.txt" file as attachment.
 
Note: every time the task 1 will run it will over write the Replication_report.txt file. After that 2nd task will send it for you.

Hope it will help you.
0
 
cwstad2Author Commented:
hi I can't get the code to work it just opens up the text file
0
Improved Protection from Phishing Attacks

WatchGuard DNSWatch reduces malware infections by detecting and blocking malicious DNS requests, improving your ability to protect employees from phishing attacks. Learn more about our newest service included in Total Security Suite today!

 
Santosh GuptaCommented:
Hi,

you mean "repadmin.exe /replsummary > C:\reports\Replication_report.txt" ??
0
 
cwstad2Author Commented:
That was on the powershell.  but I have tried the scheduled task and no output

thanks
0
 
Santosh GuptaCommented:
Hi,

do you have the C:\reports, seems not, then change the output path of file.
 or just use

repadmin.exe /replsummary > Replication_report.txt

create a batch file with above command. once success, put that into scheduler as task one.
0
 
cwstad2Author Commented:
Hi yes i have created the reports folder on C:\ will try the batch tomorrow
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.