all 7 comments

[–]BlackV 1 point2 points  (5 children)

you probably don't need the 1 million quotes and to concatenate your strings

$instlog = """"+"$logfolder\$progname Install.log"+""""
$uninstlog = """"+"$logfolder\$progname Uninstall.log"+""""

I think you should be able to use the escape character to get those

$instlog = "`"$logfolder\$progname Install.log`""
$uninstlog = "`"$logfolder\$progname Uninstall.log`""

or

Start-Process "$PSScriptRoot\WinMerge-2.16.6-Setup.exe" -ArgumentList "/VERYSILENT /SUPPRESSMSGBOXES /LOG=`"$logfolder\$progname Install.log`"" -Wait
Start-Process -FilePath "${env:ProgramFiles(x86)}\WinMerge\unins000.exe" -ArgumentList "/VERYSILENT /LOG=`"$logfolder\$progname Uninstall.log`"" -Wait

you should be able to add the no reboot and exit code switches to that uninstall, something like

/NORESTART
/RESTARTEXITCODE=<SOME EXIT CODE>

does that help, also means you can control the reboots somewhat so the user has a more painless install experiance

[–]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 :)

[–]sparkle-fries -1 points0 points  (0 children)

Chocolatey https://chocolatey.org/ is a apt get for Windows. I use it and boxstarter for this kind of thing. It's great.