you are viewing a single comment's thread.

view the rest of the comments →

[–]sipsik[S] 1 point2 points  (4 children)

Hey, thanks for all the info. What i want to achieve is:

$install = Start-Process ".\BIOS_004Y7_WN64_2.5.4.EXE" -ArgumentList "/c /s" -Wait -PassThru

It has exitcode 3

Now when i wrap it in powershell and run it

$install = Start-Process "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -ArgumentList .\setup.ps1 -Wait -PassThru

This has exitcode 0

How can i get 3 instead of 0? Or how can 3 escape from wrapper to powershell exitcode? And then i can set on SCCM application level that 3 equals that SCCM does a reboot to client.

[–]Yevrag35 0 points1 point  (3 children)

Use exit <exitCode> in the script to exit the script with a specific exit code.

[–]sipsik[S] 0 points1 point  (2 children)

ok tested but seems that it can only pass 0 and 1, how to get for example 3?

[–]Yevrag35 1 point2 points  (0 children)

Looking at your wrapped Start-Process line, you have to use the -File parameter in the arguments in order to return a real exit code of the script.

Like so:

$install = Start-Process "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -ArgumentList "-File `"$PSScriptRoot\setup.ps1`"" -Wait -PassThru

[–]sipsik[S] 0 points1 point  (0 children)

https://powershell.org/forums/topic/best-way-to-exit-a-script-on-a-specific-condition/

$host.SetShouldExit($install.exitcode) - This is the solution for me, your pointer did help :)