Powershell Call MSI with Arguments

后端 未结 5 483
旧巷少年郎
旧巷少年郎 2020-12-07 04:09

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.

5条回答
  •  独厮守ぢ
    2020-12-07 04:49

    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
    

提交回复
热议问题