Script to get " Scheduled task info through mail"

This topic contains 5 replies, has 4 voices, and was last updated by  Mark Prior 2 years, 1 month ago.

  • Author
  • #38738

    Keshav Prasad


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

    Thanks in Advance.

  • #38741

    Paul Frankovich

    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.

  • #38754

    Mark Prior

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

    this script was a godsend

  • #38800


    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.

  • #38821

    Keshav Prasad

    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.

  • #38826

    Mark Prior
    ###Get Task Status
    $mailcontent = c:\scripts\.\Get-ScheduledTask.ps1 -ComputerName eurevxa01| Where-Object {$ -ne 'bginfo' -and $_.userid -eq 'GLOBAL\LDC-KVS.Service' -and $_.lasttaskresult -ne '0'} | Select-Object name, Author, State, Userid, lastruntime, lasttaskresult, nextruntime | Out-String
    $smtpServer = ""
    $From = ""
    #$Email = ""
    $Email = ""
    $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: []
    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

You must be logged in to reply to this topic.