我想我正在为一件非常简单的事情而头晕目眩。我已经研究了两天,不幸的是我无法弄清楚。
问题是我在使用 MDT 部署 Windows 系统时使用了 Powershell 脚本。该脚本在任务序列中最后被调用。在脚本中,我要求重新启动并重试任务,因为应用程序(戴尔更新工具)需要重新启动。
这部分有效,因为在 MDT TS 中它知道它需要重新启动并且还需要重新启动任务。机器重新启动,然后重新运行相同的任务序列,但脚本从未被触发,而 SMSTS.log 确实表示它已成功启动并以代码 0 退出。
然后我注意到退出代码始终为 0,而我在脚本中对此进行了更改。然后我发现我的powershell脚本的返回码有问题,并尝试了以下方法:
测试脚本:
$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.log 中表示它以代码 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)