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

 
Senior Moderator
9 months, 2 weeks ago.

  • Author
    Posts
  • #121522

    Participant
    Topics: 36
    Replies: 149
    Points: 437
    Helping Hand
    Rank: Contributor

    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

    Senior Moderator
    Topics: 8
    Replies: 1009
    Points: 3,281
    Helping Hand
    Rank: Community Hero

The topic ‘Include Sql Agent job only if invoked by service account’ is closed to new replies.