Solved

PowerShell SQL Job Failure

Posted on 2014-07-25
1
547 Views
Last Modified: 2014-08-13
I have a PowerShell job which is continuously failing when running it in SQL Server. The error message is not giving me any insight at all. It is just stating that the step is failing.

I have inherited this job from a previous owner and am not sure exactly what it is doing. Any help or suggestions would be appreciated here.

Script

if ('$(ESCAPE_SQUOTE(INST))' -eq 'MSSQLSERVER') {$a = '\DEFAULT'} ELSE {$a = ''};
(Get-Item SQLSERVER:\SQLPolicy\$(ESCAPE_NONE(SRVR))$a).EraseSystemHealthPhantomRecords()


Thanks In Advance
0
Comment
Question by:VitaminD
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 17

Accepted Solution

by:
Barry Cunney earned 500 total points
ID: 40219480
Hi VitaminD,
There is a MS Support article which refers to EraseSystemHealthPhantomRecords()
http://support.microsoft.com/kb/955726

and the line of script that you posted is similar to what is in one of the steps in the standard system job 'syspolicy_purge_history'

Another idea, you could put the job code in  a try...catch block to get more diagnostic information about the error, but be careful not to modify any system jobs and if making any modifications make good backups first.
 try
   {
   
    # DO SCRIPT STUFF HERE
   

   }
   catch [Exception]
   {
       
        # log errors to file
      $newline = $CurrentDateTime.ToString() + "|" + $_.Exception.Message
        Add-Content -Path "c:\ERRORS.log" -Value $newline
   
   }
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question