Client Management Suite

 View Only
  • 1.  How to get correct return code from a PowerShell script task

    Posted Oct 13, 2016 10:35 AM

    I cannot get the correct return code from PowerShell script tasks in Altiris 8. no matter what the exitcode the scirpt always returns succeeded and I need it to trap errors.

    Example Powershell script that always succeeds, taken from another post that states this did work in 7.x. The script output shows 99 but the Status is always Completed and the Return Code is 0. Has anyone ever got this to work as it should?

    function ExitWithCode 

        param 
        ( 
            $errorcode
        )

    write $errorcode

        $host.SetShouldExit($errorcode) 
        exit 

    }

    ExitWithCode 99



  • 2.  RE: How to get correct return code from a PowerShell script task
    Best Answer

    Posted Oct 13, 2016 01:33 PM

    maybe I am not understanding the question.  if you want to set an exit code all you need to do is call exit with a code in ()

    here is one that should return 9

    get-content c:\temp\test.txt
    Exit(9)

    powershell will intepret that as a failure. of course but you can test paths etc and return what you want.

     

     

     



  • 3.  RE: How to get correct return code from a PowerShell script task

    Posted Oct 14, 2016 12:51 PM

    Thanks, not sure what was happening for me, I tried exactly that and didn't get the result but it looks like it was just a bug in the earlier script so that the errorlevel never got returned. No bug in Altiris...