PowerShell For DBA Part-7 (Agent job monitoring and formatting HTML)

Watch Part-1Part-2Part-3Part-4Part-5, Part-6

 

Scripts

Get-DbaAgentJob -SQLinstance localhost,localhost\SQL2017|Select *
Get-DbaAgentJob -SQLinstance localhost,localhost\SQL2017|Select Computername,Name,CurrentRunStatus,LastRunOutcome | ConvertTo-Html |
Out-File -FilePath D:\PowerShell\AgentJob.html

Invoke-Expression D:\PowerShell\AgentJob.html

Get-DbaAgentJob -SQLinstance localhost,localhost\SQL2017|Where-Object {$_.LastRunOutcome -eq "Failed" -AND $_.LastRunDate -ge (get-date).Addminutes(-45)}|Select Computername,Name,CurrentRunStatus,LastRunOutcome |
ConvertTo-Html | Out-File -FilePath D:\PowerShell\AgentJob.html

*********************************************************************

$Header = @"
<style>
TABLE {border-width: 1px; border-style: solid; border-color: black;}
TH {border-width: 1px; padding: 1px; border-style: solid; border-color: black; background-color: #9999CC;}
TD {border-width: 1px; padding: 1px; border-style: solid; border-color: black;}
</style>
"@
Get-DbaAgentJob -SQLinstance localhost,localhost\SQL2017|? {$_.LastRunOutcome -eq "Failed"}|Select Computername,Name,CurrentRunStatus,LastRunOutcome |
ConvertTo-Html -Head $Header | Out-File -FilePath D:\PowerShell\AgentJob.html

Invoke-Expression D:\PowerShell\AgentJob.html

Follow me:

Blog: http://Sqldepository.com

YouTube : Sql depository

Facebook: https://www.facebook.com/sqldepository/

Google+ :https://plus.google.com/u/0/107093915534620159617

 

Author: Sauras Pandey

Sauras Pandey is an MCP, SQL Server DBA/Architect with 9+ years of experience working in a variety of environments

6 thoughts on “PowerShell For DBA Part-7 (Agent job monitoring and formatting HTML)

  1. Excellent learning …. when I had tried getting below error. Kindly advise

    PS C:\Users\dba939> Find-DbaAgentJob -SqlInstance INSTANCE-1|select*
    select* : The term ‘select*’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included,
    verify that the path is correct and try again.
    At line:1 char:43
    + Find-DbaAgentJob -SqlInstance INSTANCE-1|select*
    + ~~~~~~~
    + CategoryInfo : ObjectNotFound: (select*:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Leave a Reply

Your email address will not be published.