Powershell Call MSI with Arguments

Question:

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

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

Using a variable to define InstallDir

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

Tried this also, Single Quotes with Quotes on Path

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

Using single quotes on InstallDir

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

Using single quotes on the outside

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.

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

Answer:

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.


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.

Source:

Powershell Call MSI with Arguments by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply