Gathering failed job history using power shell

How to use this powershell script:
    - Launch SQL Server PowerShell ( Start -> Run -> sqlps.exe)
    - Copy the following powershell script and save to file (Ex c:\JobHistory.ps1)
    - in SQL powershell window, type in script file path ( Ex: c:\JobHistory.ps1) to run the script
 replace "machine\instance" with 
      default instance - machinename\DEFAULT
      named instance - machinename\instancename


 1: $instance = "machinename\instancename"
 3: $psPath = "SQLSERVER:\SQL\$instance\JobServer"
 4: dir $psPath\Jobs | foreach { $_.EnumHistory() }  | where-object { $_.RunStatus -ne 1}



This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified  t


Comments (0)

Skip to main content