header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
How does a PowerShell SQL Server Agent Step signal failure?
Last Post 01 Sep 2010 06:12 PM by Chad Miller. 1 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
Don DeCostaUser is Offline
New Member
New Member
Posts:2
Avatar

--
01 Sep 2010 12:10 PM

    As a simple example, let's say I'm using a PowerShell Step in a SQL Sever Agent job to check for the existence of a file.

    If the file does not exist, how does the PowerShell Step signal to the Agent Job that the step failed so that Agent can retry the step according to the step's settings?

    I could just let PowerShell loop and sleep until the file arrives but I want to use SQL Agent as it was intended and have it handle failure and success and retries and continue to this step on success or that step on failure, etc.

    Chad MillerUser is Offline
    Basic Member
    Basic Member
    Posts:160
    Avatar

    --
    01 Sep 2010 06:12 PM
    A throw will cause the job step to fail. In fact any exception which isn't handled will. See this post on Server Fault: Post

    if (!(test-path c:\myfolder\myfile.txt))
    { throw 'file does not exist'}

    I would probably go with a cmdexec (Operating System) job step and call regular PowerShell.exe, then use
    System.IO.FileSystemWatcher + Register-ObjectEvent + Wait-Event rather than rely on Agent.
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer