Failed SQL job info from PS to sql table

  • Hi All,

    Please have a look at the below link and help me to get the details (as 4 Columns) into a SQL Server table instead of Mail as I can make a SSR report from the data.

    SERVER =

    JOB =

    LASTRUN =

    LASTRUNDATE =

    http://www.sqlservercentral.com/blogs/sqlsandwiches/2012/01/29/find-failed-sql-jobs-with-powershell/

    Regards

    Srikanth Reddy Kundur

  • Have you tried to change the part where it says

    $msg.body = $msg.body + "`n `n FAILED JOB INFO:... [snip]

    to something like this

    $sql = "insert YourTableName (server, job, last_run_status, last_run_date)

    values ('$sqlserver', '$jobname', '$jobLastRunOutcome', '$jobLastRun');"

    then run that into your SQL Server? Adjusted, of course, for your table structure.

    If you have something that's failing send the code and error message and maybe someone here could help a little more.

  • Changed the code as suggested, the job executes successful but no records are getting inserted, Can anyone help on the script please.

    Regards

    S.R.Kundur

  • Paste your complete PS code here. Also, is there a specific reason not to use sysjobshistory and sysjobs tables for reporting needs?

    Raunak J

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply