I have a SQL Agent job that dynamically builds a .ps1 to copy files, then uses a CmdExec job step to check it exists and run it. If there's nothing to copy the .ps1 won't get built. But if I have an invalid path or other .ps1 error, the CmdExec job step still reports success. I don't know how to get the CmdExec to catch an error in the .ps1 .
if exists c:\folder\BatchCopy.ps1 Powershell -file "c:\folder\BatchCopy.ps1"