小编kin*_*13p的帖子

带参数的Powershell调用MSI

我正在使用Powershell脚本来安装Autodesk产品,但遇到了一些麻烦。

我尝试了许多不同的方法,并不断遇到错误。

使用双引号

(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
Run Code Online (Sandbox Code Playgroud)

错误无法验证参数'ArgumentList'上的参数参数为null或为空。

使用变量定义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
Run Code Online (Sandbox Code Playgroud)

这样做我得到msiexec / option必需参数错误。

也在单引号和路径引号上尝试过

(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
Run Code Online (Sandbox Code Playgroud)

我收到一个找不到接受参数C:\ Program的位置参数

在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
Run Code Online (Sandbox Code Playgroud)

这样做我得到msiexec / option必需参数错误。

在外面使用单引号

(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
Run Code Online (Sandbox Code Playgroud)

如果执行此操作,它将阻止$ …

powershell

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

powershell ×1