Script to get " Scheduled task info through mail"

This topic contains 5 replies, has 4 voices, and was last updated by Profile photo of Mark Prior Mark Prior 6 months, 4 weeks ago.

  • Author
    Posts
  • #38738
    Profile photo of Keshav Prasad
    Keshav Prasad
    Participant

    Friends

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

    Thanks in Advance.

  • #38741
    Profile photo of Paul Frankovich
    Paul Frankovich
    Participant

    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
    Profile photo of Mark Prior
    Mark Prior
    Participant

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

    this script was a godsend

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

  • #38800
    Profile photo of AK
    AK
    Participant

    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
    Profile photo of Keshav Prasad
    Keshav Prasad
    Participant

    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
    Profile photo of Mark Prior
    Mark Prior
    Participant
    ###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

You must be logged in to reply to this topic.