MDT powershell task fails, but returns return code 0

Ben Wosjke 136 Reputation points
2020-11-11T06:25:15.117+00:00

Hi all,
MDT 8456 with 2004 patch, running a task sequence with a powershell script - even if that script fails, a return code of "0" is still returned to the TS.

If the script fails, i need the TS to fail..

From the logs

<![LOG[File \server\MDT4\Scripts\Custom\DeviceCompat\CheckCompat.ps1 cannot be loaded.
The file \server\MDT4\Scripts\Custom\DeviceCompat\CheckCompat.ps1 is not digitally signed. You cannot run this script on the current system. For more information about running scripts and setting execution policy, see about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170.\]LOG\]!>\<time="18:38:58.000+000" date="11-03-2020" component="TaskSequencePSHost" context="" type="3" thread="" file="TaskSequencePSHost">
<![LOG[At line:1 char:3

  • . "\server\MDT4\Scripts\Custom\DeviceCompat\CheckCompat.ps1
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~]LOG]!><time="18:38:58.000+000" date="11-03-2020" component="TaskSequencePSHost" context="" type="3" thread="" file="TaskSequencePSHost">
    <![LOG[SecurityError: (:) [], PSSecurityException]LOG]!><time="18:38:58.000+000" date="11-03-2020" component="TaskSequencePSHost" context="" type="3" thread="" file="TaskSequencePSHost">
    <![LOG[TSHOST: Script completed with return code 0]LOG]!><time="18:38:58.000+000" date="11-03-2020" component="TaskSequencePSHost" context="" type="1" thread="" file="TaskSequencePSHost">

Im a bit baffled as to why this is returning an error code of 0 when it cannot run due to signing restrictions!

Continue on error is not selected for this step.

Microsoft Deployment Toolkit
Microsoft Deployment Toolkit
A collection of Microsoft tools and documentation for automating desktop and server deployment. Previously known as Microsoft Solution Accelerator for Business Desktop Deployment (BDD).
902 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Rick Someone 411 Reputation points
    2020-11-12T17:22:23.573+00:00

    The only immediate thing that comes to mind is, first, you're running this from the desktop I assume...

    Also, do you have an execute restriction entry in your PS? Such as,
    set-executionpolicy unrestricted -force

    Also, in your Task, where the PS is, click on Options tab and make sure Continue on Error is not checked.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.