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
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 = ""
$from = ""
 Send-MailMessage -SmtpServer -From $from  -To $to -Subject 'repl Summary' -Body $body
Santosh GuptaConnect With a Mentor Commented:

if you are using windows 2008 or 2012 then you can achieve this goal by using the "Task Scheduler".
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.
cwstad2Author Commented:
hi I can't get the code to work it just opens up the text file
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:

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

Santosh GuptaCommented:

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.
cwstad2Author Commented:
Hi yes i have created the reports folder on C:\ will try the batch tomorrow
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.