Skip to content

Instantly share code, notes, and snippets.

@SQLvariant
Created February 3, 2017 21:26
Show Gist options
  • Save SQLvariant/e13c69ebab8843a948f9f1250cd7ea8a to your computer and use it in GitHub Desktop.
Save SQLvariant/e13c69ebab8843a948f9f1250cd7ea8a to your computer and use it in GitHub Desktop.
<#1#>
Get-Command -Module SqlServer -Noun SqlAgent*
<#2#>
Get-SqlAgentJobHistory -ServerInstance localhost, localhost\SQL2016 -Since Midnight -OutcomesType Failed
<#3#>
Get-SqlAgentJobHistory -ServerInstance localhost, localhost\SQL2016 -Since Midnight -OutcomesType Failed |
Out-GridView
<#4#>
Get-SqlAgentJobHistory -ServerInstance localhost, localhost\SQL2016 -StartRunDate (get-date).AddHours(-12) -OutcomesType Failed
<#5#>
Get-SqlAgentJobHistory -ServerInstance localhost, localhost\SQL2016 -StartRunDate 2017-01-31 -OutcomesType Failed
<#6#>
$ServerList = DIR -Recurse 'SQLSERVER:\SQLRegistration\Database Engine Server Group\Host'|
WHERE {$_.Mode -ne 'd'}
<#7#>
Get-SqlAgentJobHistory -ServerInstance $ServerList.Name -StartRunDate (get-date).AddHours(-12) -OutcomesType Failed |
Out-GridView
<#8#>
foreach ($ServerList IN dir -recurse SQLSERVER:\SQLRegistration\'Database Engine Server Group'\ )
{
Get-SqlAgentJobHistory -ServerInstance $ServerList.Name -StartRunDate (get-date).AddHours(-12) -OutcomesType Failed |
Format-Table -AutoSize
}
<#9#>
Get-SqlAgentJob -ServerInstance localhost
<#10#>
Get-SqlAgentJob -ServerInstance localhost |
Out-GridView
<#11#>
Get-SqlAgentJob -ServerInstance localhost |
SELECT *
<#12#>
Get-SqlAgentJob -ServerInstance localhost |
Where { $_.IsEnabled -eq $true -and $_.LastRunOutcome -eq 'Failed' }
<#13#>
Get-SqlAgentJob -ServerInstance localhost |
Where { $_.DateCreated -gt (get-date).AddDays(-7) }
<#14#>
Get-SqlAgentJob -ServerInstance localhost | Get-Member -MemberType Methods
<#15#>
Get-SqlAgentJob -ServerInstance localhost, localhost\SQL2016 |
Where-Object { $_.IsEnabled -eq $true -and $_.LastRunOutcome -eq 'Failed' } |
Out-GridView -PassThru |
foreach {$_.Start()}
<#16#>
Get-SqlAgentJob -ServerInstance localhost, localhost\SQL2016 |
Out-GridView -PassThru |
foreach {
$_.OwnerLoginName = 'sa'
$_.Alter()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment