PowerShell - Run external program with parameters
I'm trying to run an InstallShield setup with a series of parameters from a PowerShell script:
$dir = Split-Path $scriptpath & "$dir\policeROADSsetup.exe" -s -SMS -f1`"$dir\Win7\setup.iss`"
The executable runs, MSIEXEC reports success, but the setup returns an exit code of -3 and the software is not installed. I can put this code into a CMD file:
"%~dp0\policeROADSsetup.exe" -s -SMS -f1"%~dp0\WinXP\setup.iss"
And call it in the PowerShell script:
& "$dir\InstallUA.cmd"
And this works just find. Software installes, exit code 0. Any suggestions on how I can get this to install without have to resort to a one-line CMD file? Thanks a bunch.
Answers (2)
Try this:
$install = start-process -filepath "policeROADsetup.exe" -argumentlist '-s -SMS -f1 \Win7\setup.iss' -wait -passthru
Not sure about the relative path reference for the setup.iss file, but worst case scenario, move it to the same folder as the setup.exe?
Also, you can use double quotes inside the argumentlist if needed because it's enclosed in single quotes. You won't be able to resolve variables in there though.
Comments:
-
I was able to get this to work using some of your suggestions. Thank you very much! Here is the code I ended up with:
$scriptpath = $MyInvocation.MyCommand.Path
$dir = Split-Path $scriptpath
$program = "$dir\policeROADSsetup.exe"
$arguments = "-s -SMS -f1`"$dir\Win7\setup.iss`""
Start-Process -FilePath "$program" -ArgumentList "$arguments" -Wait -PassThru - RyanCorum 12 years ago -
No problems.
You could improve your script by assigning a variable to "Start-Process" and then check it's exitcode to determine whetever it was successful. Otherwise there is no point in the -passthru argument.
Don't know what you're deploying through, but without proper exitcode handling when deploying software with powershell scripts through SCCM - you'll have a bad time. - Ifan 12 years ago -
The complete script is over 100 lines, this is just a little code-snipit. I am capturing the error code and am getting a very predictable deployment with valid exit codes. - RyanCorum 12 years ago
-
Awesome. Good job man ;) - Ifan 12 years ago
I am not sure what you have written in other parts of your script.
Try using a different script. Use this command line in the script here:
http://msiworld.blogspot.com.au/2012/01/my-first-powershell-script.html