Solved

PowerShell SQL Job Failure

Posted on 2014-07-25
1
509 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
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
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…
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.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

820 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