4

I'm working on a powershell script to install Autodesk products and I am having some trouble.

I've tried this many different ways and keep running into errors.

Using double quotes

(Start-Process "msiexec.exe" -ArgumentList ""/i $dirFiles\ABDS2017\Img\x64\RVT\RVT.msi INSTALLDIR="C:\Program Files\Autodesk\" ADSK_SETUP_EXE=1 /qb!"" -NoNewWindow -Wait -PassThru).ExitCode

Error Cannot validate argument on parameter 'ArgumentList' Argument is null or empty.

Using a variable to define InstallDir

$RevitInstallDir = "C:\Program Files\Autodesk\"
    (Start-Process "msiexec.exe" -ArgumentList "/i $dirFiles\ABDS2017\Img\x64\RVT\RVT.msi INSTALLDIR=$RevitInstallDir ADSK_SETUP_EXE=1 /qb!" -NoNewWindow -Wait -PassThru).ExitCode

Doing this I get the msiexec /option Required Parameter error.

Tried this also, Single Quotes with Quotes on Path

(Start-Process "msiexec.exe" -ArgumentList "/i $dirFiles\ABDS2017\Img\x64\RVT\RVT.msi INSTALLDIR="C:\Program Files\Autodesk\" ADSK_SETUP_EXE=1 /qb!" -NoNewWindow -Wait -PassThru).ExitCode

I receive A positional parameter cannot be found that accepts argument C:\Program

Using single quotes on InstallDir

(Start-Process "msiexec.exe" -ArgumentList "/i $dirFiles\ABDS2017\Img\x64\RVT\RVT.msi INSTALLDIR='C:\Program Files\Autodesk\' ADSK_SETUP_EXE=1 /qb!" -NoNewWindow -Wait -PassThru).ExitCode

Doing this I get the msiexec /option Required Parameter error.

Using single quotes on the outside

(Start-Process "msiexec.exe" -ArgumentList '/i $dirFiles\ABDS2017\Img\x64\RVT\RVT.msi INSTALLDIR="C:\Program Files\Autodesk\" ADSK_SETUP_EXE=1 /qb!' -NoNewWindow -Wait -PassThru).ExitCode

If I do this, it prevents the $dirFiles variable from working.

The reason I'm using Start-Process is because I have many installers one after the other and I want one installer to wait till the one before it finishes. Any help would be appreciated! Thanks

EDIT: Nevermind, I figured it out.

(Start-Process "msiexec.exe" -ArgumentList "/i $dirFiles\ABDS2017\Img\x64\RVT\RVT.msi INSTALLDIR=""C:\Program Files\Autodesk\"" ADSK_SETUP_EXE=1 /qb!" -NoNewWindow -Wait -PassThru).ExitCode

Double Quotes around the Install Dir

Got the idea from here. https://blogs.technet.microsoft.com/heyscriptingguy/2015/06/20/weekend-scripter-understanding-quotation-marks-in-powershell/

Thanks

king13p
  • 71
  • 1
  • 1
  • 5

6 Answers6

11

Don't bother with Start-Process unless you need to run a process with elevated privileges. Use the call operator and splatting instead. The exit code of the command is stored in the automatic variable $LastExitCode.

$params = '/i', "$dirFiles\ABDS2017\Img\x64\RVT\RVT.msi",
          'INSTALLDIR="C:\Program Files\Autodesk"', 'ADSK_SETUP_EXE=1',
          '/qb!'
& msiexec.exe @params
$LastExitCode

Unfortunately you cannot tell msiexec.exe to wait for an installation to complete, and the call operator also doesn't enforce synchronous execution. If you need to wait for the installation to complete before proceeding you need something like the CMD-builtin start command or Start-Process. I would still recommend defining the parameters as an array, though.

$params = '/i', "$dirFiles\ABDS2017\Img\x64\RVT\RVT.msi",
          'INSTALLDIR="C:\Program Files\Autodesk"', 'ADSK_SETUP_EXE=1',
          '/qb!'
$p = Start-Process 'msiexec.exe' -ArgumentList $params -NoNewWindow -Wait -PassThru
$p.ExitCode
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • 1
    This may have worked when you posted it but I am not able to make this work today. – phydeauxman Nov 27 '18 at 19:02
  • 1
    @phydeauxman Then please post a new question. Reference this question, show a [mcve] of the code you were running, and describe as detailed as possible how you were "not able to make this work". – Ansgar Wiechers Nov 27 '18 at 22:37
  • 2
    I don't believe the method defined with splatting waits for the msi to complete installation... – code4cause Feb 19 '19 at 22:54
3

I figured out the answer. Double Quotes around the path for installdir fixed it for me.

Thanks

(Start-Process "msiexec.exe" -ArgumentList "/i $dirFiles\ABDS2017\Img\x64\RVT\RVT.msi INSTALLDIR=""C:\Program Files\Autodesk\"" ADSK_SETUP_EXE=1 /qb!" -NoNewWindow -Wait -PassThru).ExitCode
king13p
  • 71
  • 1
  • 1
  • 5
1

This worked for me, had the same issue

$exeScriptDir = $PSScriptRoot

Function installMSI {
    $msifile = "$exeScriptDir\3D Access\OSNME.msi"
    $msiargs = @(
        "/i"
        "`"$msifile`""
        'INSTALLDIR="C:\PRGS\PTC\Creo Elements\Direct 3D Access 20.1\"'
        "MELS=LOCALHOST"
        "/qn"
    )
    $installcommand = (start-process msiexec.exe -ArgumentList $msiargs -wait -PassThru)
}   

installMSI 
0

Any luck with storing the entire argument in a variable then passing it to start-process?

example:

$argument = "/i $dirFiles\ABDS2017\Img\x64\RVT\RVT.msi INSTALLDIR='C:\Program Files\Autodesk\' ADSK_SETUP_EXE=1 /qb!"
(start-process msiexec.exe -argumentlist $argument).ExitCode
Luisrorta
  • 139
  • 5
0

This would be my recommendation for the first code snippet you provided, use single quotes inside of double quotes...

(Start-Process "msiexec.exe" -ArgumentList "/i $dirFiles\ABDS2017\Img\x64\RVT\RVT.msi INSTALLDIR='C:\Program Files\Autodesk\' ADSK_SETUP_EXE=1 /qb!" -NoNewWindow -Wait -PassThru).ExitCode

If this receives an error, you are missing an important parameter.

cet51
  • 1,196
  • 2
  • 11
  • 29
0

In order to understand how to "quote" the parameters for start-process here is a sample of code to start the unattended installation of vmtools

the command i wanted to run in a powershell:

setup.exe  /l /v"/qn REBOOT=R ADDLOCAL=ALL REMOVE=Hgfs,Unity,BootCamp,SVGA"

The powershell sample:

Start-Process -FilePath "$vmtoolspath\setup.exe" -ArgumentList "/l /v ""/qn REBOOT=R ADDLOCAL=ALL REMOVE=Hgfs,Unity,BootCamp,SVGA"" " -Wait
Max
  • 161
  • 2
  • 4