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: Add Windows NTFS Permissions to File or Folder

The re-usable function: $path='C:\Windows\servicing' $accountsToAdd='Administrators' $permissions='Full' function addNtfsPermissions ($path,$accountsToAdd,$permissions){ $acl = Get-ACL $path $accessRule=New-Object System.Security.AccessControl.FileSystemAccessRule($accountsToAdd,$permissions,"Allow")…

SQL: Backup Database and Purge It From SQL Server

/* Make a Final Backup of Database, Purge Its Backup and Restore History, and Remove…

Install Apps on Remote Computers via WinRM & Chocolatey

Version A: [string[]]$computers=@( 'SERVER01', 'SERVER02', 'SERVER03' ) [string]$chocoAppName='pgadmin4' [version]$minVersion='6.0' $results=[hashtable]@{} foreach ($computer in $computers){ $session=new-pssession…