Quantcast
Channel: SQLServerCentral » Programming » Powershell » Latest topics
Viewing all articles
Browse latest Browse all 467

SQL Agent job not failing when Powershell script errors

$
0
0
First time using Powershell. And I'm trying to execute via SQL Agent job. So I don't know if I have something wrong in my Powershell script or my SQL Agent job or Both.SQL Server 2008 R2 PowerShell V2.0Have tried in Powershell the Trap and Try catch with a Throw and Exit 1. But for some reason the SQL Agent job doesn't fail.In Powershell I have:$ErrorActionPreference = "Stop"-ea stopIn Sql agent job I have:Command:powershell.exe -File "\\mypowershell\PSscript.ps1" -param1 "\myfilelocation" -param2 "\mydestination" -ErrorAction StopAdvanced:On failure action: Quit the job reporting failureNow when the Powershell script fails I want the sql agent job to fail.What am I missing?Thanks,Sqlraider

Viewing all articles
Browse latest Browse all 467

Trending Articles