Posted On September 29, 2021

PowerShell: Get SQL Job History

kimconnect 0 comments
blog.KimConnect.com >> Codes , Database >> PowerShell: Get SQL Job History
$computername='sql01'

function getSqlJobHistory($sqlServerName){
  try{
    if(!(get-module SqlServer)){
      Install-Module -Name SqlServer
    }
    Import-Module -Name SqlServer
    $sqlServerInstance=Get-SqlInstance -ServerInstance $sqlServerName
    $sqlAgent=Get-SqlAgent -ServerInstance $sqlServerInstance.Name
    $sqlJobs=$sqlAgent|Get-SqlAgentJob|Get-SqlAgentJobSchedule|?{$_.IsEnabled}
    $sqlJobs|select-object Name,ActiveStartTimeOfDay,FrequencyTypes,FrequencySubDayTypes|ft -autosize
  }catch{
    write-warning $_
    return $false
  }
}

getSqlJobHistory $computername
PS C:\Users\sqladmin1> getSqlJobHistory sql01

Name                               ActiveStartTimeOfDay FrequencyTypes FrequencySubDayTypes
----                               -------------------- -------------- --------------------
Check Database Integrity.Subplan_1 03:00:00                     Weekly                 Once
Differential Database Backups      22:00:00                      Daily                 Hour
Daily 10PM                         22:00:00                      Daily                 Once
Beginning of Month                 00:00:00                    Monthly                 Once
Schedule                           00:30:00                      Daily                 Once
syspolicy_purge_history_schedule   02:00:00                      Daily                 Once
Schedule1                          00:00:00                      Daily               Second

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

Clean Windows C Volume

Have you ever ran into a sluggish performance on a Windows machine that is being…

Lightbox Javascript Contents

These JavaScript codes are open source and part of many applications, such as NextGen Gallery.…

Recover Windows CD Key

Set WshShell = CreateObject("WScript.Shell")MsgBox ConvertToKey(WshShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId"))Function ConvertToKey(Key)Const KeyOffset = 52i = 28Chars = "BCDFGHJKMPQRTVWXY2346789"DoCur =…