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.

0 Comments   [ + ] Show comments

Answers (2)

Answer Summary:
Posted by: Ifan 9 years ago
Second Degree Green Belt

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.

  • 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 9 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 9 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 9 years ago
  • Awesome. Good job man ;) - Ifan 9 years ago
Posted by: piyushnasa 9 years ago
Red Belt

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:


This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ