Quantcast
Viewing all articles
Browse latest Browse all 2021

How to get correct return code from a PowerShell script task

I need a solution

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

0

Viewing all articles
Browse latest Browse all 2021

Trending Articles