Include Sql Agent job only if invoked by service account

Welcome Forums General PowerShell Q&A Include Sql Agent job only if invoked by service account

This topic contains 1 reply, has 2 voices, and was last updated by

 
Participant
1 month ago.

  • Author
    Posts
  • #121522

    Participant
    Points: 123
    Rank: Participant

    I've got a script that reports on failed Sql Agent jobs, run nicely, except that when a Job fails, we'll work on fixing it and usually rerun it....if it fails when we run it, I want that excluded from the report.

    I want this included:

    RunDate : 11/3/2018 8:01:28 AM
    StepID : 0
    Server : server\instance
    JobName : ourjob
    StepName : (Job outcome)
    Message : The job failed. The Job was invoked by User domain\serviceaccount. The last step to run was step 3
    
    

    But I want to exclude this:

    RunDate : 11/3/2018 8:01:28 AM
    StepID : 0
    Server : server\instance
    JobName : ourjob
    StepName : (Job outcome)
    Message : The job failed. The Job was invoked by User domain\user. The last step to run was step 3
    
    

     

    I'm using this cmd:

    Get-SqlAgentJobHistory -ServerInstance $SqlServer -OutcomesType Failed -StartRunDate ((Get-Date).AddMinutes(-15)) | `
    Select | select RunDate,StepID,Server,JobName,StepName,Message
    
    
  • #122895

    Participant
    Points: 809
    Helping Hand
    Rank: Major Contributor

You must be logged in to reply to this topic.