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

PowerShell: Get Quorums of All Clusters in the Domain

# getClusterQuorum.ps1 function getClusterQuorum{ $allClusters=(get-cluster -domain $env:USERDNSDOMAIN).Name $results=@{} foreach ($cluster in $allClusters){ $quorum=Get-ClusterQuorum -Cluster $cluster…

PowerShell: ADFS Backup and Restore

# AD FS Backup and Restore # Reference documentation: https://learn.microsoft.com/en-us/windows-server/identity/ad-fs/operations/ad-fs-rapid-restore-tool # Set Variables $filePassword="password" $adfsToolDownload="https://download.microsoft.com/download/6/8/A/68AF3CD3-1337-4389-967C-A6751182F286/ADFSRapidRecreationTool.msi"…

Reset Windows Update Tool

:: ==================================================================================:: Re-posting this here because I admire the good work by Sir Manuel Gil::…