Solved

PowerShell SQL Job Failure

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

Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
encrypt SQL Server 2008 port 1433 3 41
I am new to using JSON in SQL Server 2 53
Sql Query 29 30
SQL Percentage Formula 7 29
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how the fundamental information of how to create a table.

738 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