Script to get " Scheduled task info through mail"

Friends

how I can use
get-scheduledtaskinfo
To capture from remote computer and receiving it through mail.

Thanks in Advance.

Try using a CIM Session to connect to the remote machine with the Get-ScheduledTaskInfo. Collect your info into your email and send it with the Send-MailMessage cmdlet.

i was after similar the other month, more of a pain than it should be to be honest :slight_smile:

this script was a godsend

https://gallery.technet.microsoft.com/scriptcenter/Get-Scheduled-tasks-from-3a377294

It is such a PITA. For a quick start go with the script Mark mentioned above, that is ,if you get it to work without errors.

Thank You,

yes I am using it. it’s working fine.
I want the same output in mail.

.\scheduled-task.ps1 -ComputerName | Where-Object {$_.Name -eq ‘’} | export-csv C:\tst.csv | Send-MailMessage -To -Subject “” -Attachments “C:\tst.csv” -From -SmtpServer

I tried above but getting empty mail.
any suggestion.

###Get Task Status
$mailcontent = c:\scripts\.\Get-ScheduledTask.ps1 -ComputerName eurevxa01| Where-Object {$_.name -ne 'bginfo' -and $_.userid -eq 'GLOBAL\LDC-KVS.Service' -and $_.lasttaskresult -ne '0'} | Select-Object name, Author, State, Userid, lastruntime, lasttaskresult, nextruntime | Out-String


##Constants
$smtpServer = "smtp.contoso.com"
$From = "EUREVXA01Tasks@contoso.com"
#$Email = "mark.prior@contoso.com"
$Email = "EMEA.IT-Messaging@contoso.com"
$SubjectCPY = "EV Task Status"
$Body = "$mailcontent"

#Email Content
if ($mailcontent) {Send-Mailmessage -smtpServer $smtpServer -from $from -to $Email -subject $subjectCPY -priority High -Body $Body}

the above only fires if $mailcontent is not Null,

Here i am looking for tasks that run as “LDC-KVS.service”, that did not complete with a status of “0” and name is not “bginfo”

mail output looks like

-----Original Message-----
From: EUREVXA01Tasks@contoso.com [mailto:EUREVXA01Tasks@contoso.com]
Sent: 10 May 2016 08:00
To: EMEA IT Messaging
Subject: EV Task Status
Importance: High

Name : EV-Clear-State
Author : GLOBAL\ldc-kvs.service
State : Running
UserId : GLOBAL\ldc-kvs.service
LastRunTime : 10/05/2016 07:43:03
LastTaskResult : 267009
NextRunTime : 11/05/2016 06:45:00