Powershell在MDT任务序列中返回退出代码0或1
我想我是因为一件很简单的事而头疼。我已经做了两天了,不幸的是我想不出来 问题是,我在使用MDT部署Windows系统时使用了Powershell脚本。该脚本在任务序列中最后调用。在脚本中,我请求重新启动并重试任务,因为应用程序(Dell update tool)需要重新启动 这部分工作正常,因为在MDT TS中,它理解需要重新启动,也需要重新启动任务。计算机重新启动,然后重新运行相同的任务序列,但脚本从未被激发,而SMSTS.log确实表明它已成功启动并退出,代码为0 然后,当我在脚本中更改此代码时,我注意到退出代码始终为0。然后我发现我的powershell脚本的返回代码出错,并尝试了以下操作: 测试脚本:Powershell在MDT任务序列中返回退出代码0或1,powershell,exit-code,mdt,Powershell,Exit Code,Mdt,我想我是因为一件很简单的事而头疼。我已经做了两天了,不幸的是我想不出来 问题是,我在使用MDT部署Windows系统时使用了Powershell脚本。该脚本在任务序列中最后调用。在脚本中,我请求重新启动并重试任务,因为应用程序(Dell update tool)需要重新启动 这部分工作正常,因为在MDT TS中,它理解需要重新启动,也需要重新启动任务。计算机重新启动,然后重新运行相同的任务序列,但脚本从未被激发,而SMSTS.log确实表明它已成功启动并退出,代码为0 然后,当我在脚本中更改此代
$MyExitCode = 3010
Write-Host ('MyExitcode: [' + $MyExitCode + ']')
Write-Host ('LastExitCode: [' + $LastExitCode + ']')
Write-Host ''
Write-Host 'Setting MyExitCode to LastExitCode'
$LastExitCode = $MyExitCode
Write-Host 'New Result:'
Write-Host ('MyExitcode: [' + $MyExitCode + ']')
Write-Host ('LastExitCode: [' + $LastExitCode + ']')
Read-Host 'Debug Break'
Write-Output $_
Exit $ExitCode
以管理员身份打开CMD,然后运行以下命令
CMD> powershell.exe -ExecutionPolicy bypass -File "Z:\Applications\Test\TestRerunTask.ps1"
CMD> echo $LastExitCode
CMD> 0
将参数-File
替换为-Command
将退出代码更改为1,但仍在SMSTS中。登录时显示退出代码为0
Snippet SMSTS.log任务序列称为Test
!--------------------------------------------------------------------------------------------! TSManager 13-2-2020 11:18:41 6200 (0x1838)
Expand a string: WinPEandFullOS TSManager 13-2-2020 11:18:41 6200 (0x1838)
Executing command line: cscript.exe "%SCRIPTROOT%\ZTIApplications.wsf" TSManager 13-2-2020 11:18:41 6200 (0x1838)
Process completed with exit code 0 TSManager 13-2-2020 11:19:02 6200 (0x1838)
!--------------------------------------------------------------------------------------------! TSManager 13-2-2020 11:19:02 6200 (0x1838)
Successfully completed the action (Test) with the exit win32 code 0 TSManager 13-2-2020 11:19:02 6200 (0x1838)
Executing in non SMS standalone mode. Ignoring send a task execution status message request TSManager 13-2-2020 11:19:02 6200 (0x1838)
Set a global environment variable _SMSTSLastActionRetCode=0 TSManager 13-2-2020 11:19:02 6200 (0x1838)
Set a global environment variable _SMSTSLastActionName=Test TSManager 13-2-2020 11:19:02 6200 (0x1838)
Set a global environment variable _SMSTSLastActionSucceeded=true TSManager 13-2-2020 11:19:02 6200 (0x1838)
Clear local default environment TSManager 13-2-2020 11:19:02 6200 (0x1838)
The action (Test) requested a retry TSManager 13-2-2020 11:19:02 6200 (0x1838)
Created volatile registry entry for pending reboot initiated by this task sequence TSManager 13-2-2020 11:19:02 6200 (0x1838)
The action (Test) initiated a reboot request TSManager 13-2-2020 11:19:02 6200 (0x1838)
Executing in non SMS standalone mode. Ignoring send a task execution status message request TSManager 13-2-2020 11:19:02 6200 (0x1838)
**************************************************************************** TSManager 13-2-2020 11:19:02 6200 (0x1838)
Execution engine result code: Reboot (2) TSManager 13-2-2020 11:19:02 6200 (0x1838)
Process completed with exit code 2147945410 TSMBootstrap 13-2-2020 11:19:02 6168 (0x1818)
Exiting with return code 0x80070BC2 TSMBootstrap 13-2-2020 11:19:02 6168 (0x1818)
----------------------
... More reboot stuff ...
----------------------
Expand a string: WinPEandFullOS TSManager 13-2-2020 11:19:34 8652 (0x21CC)
Executing command line: cscript.exe "%SCRIPTROOT%\ZTIApplications.wsf" TSManager 13-2-2020 11:19:34 8652 (0x21CC)
Process completed with exit code 0 TSManager 13-2-2020 11:19:34 8652 (0x21CC)
!--------------------------------------------------------------------------------------------! TSManager 13-2-2020 11:19:34 8652 (0x21CC)
Successfully completed the action (Test) with the exit win32 code 0 TSManager 13-2-2020 11:19:34 8652 (0x21CC)
Executing in non SMS standalone mode. Ignoring send a task execution status message request TSManager 13-2-2020 11:19:34 8652 (0x21CC)
Set a global environment variable _SMSTSLastActionRetCode=0 TSManager 13-2-2020 11:19:34 8652 (0x21CC)
Set a global environment variable _SMSTSLastActionName=Test TSManager 13-2-2020 11:19:34 8652 (0x21CC)
Set a global environment variable _SMSTSLastActionSucceeded=true TSManager 13-2-2020 11:19:34 8652 (0x21CC)
Clear local default environment TSManager 13-2-2020 11:19:34 8652 (0x21CC)
经过更多的调试和谷歌搜索,我找到了我想要的答案。首先我找到了一个主题,然后是一个主题。这些话题为我指明了正确的方向。事实证明,我正在MDT任务序列中将Powershell脚本作为
应用程序运行。我发现将脚本添加为应用程序很容易,因为我可以很容易地将它们分配到任务序列,但是返回代码的魔力就消失了。ZTIapplications
脚本以powershell.exe-ExecutionPolicy bypass-Command“&{&'%deployroot%\Applications\Test\TestRerunTask.ps1';Exit$LastExitCode}”的形式运行powershell脚本
此脚本捕获返回代码,但返回代码不会传回任务序列SMSTS
,因此它假定“应用程序”已成功安装。从MDT调用脚本运行Powershell脚本
一切正常
我仍在寻找在MDT中将Powershell脚本用作应用程序的方法,以保持返回代码始终正常工作,但同时我有一个合适的解决方法,$LastExitCode
是一个Powershell。包含上次运行的基于Windows的程序的退出代码。