电源外壳的好处是您可以从shell运行任何命令行应用程序。这是og体育事物的常用方式。调用og体育程序通常与双击它相同。如果您调用MSI,它将弹出并启动og体育。

.\SQLIO.msi

You see that work but then you want it to run silently. Check for command line options with /? and see something promising. There is a /quiet option.

.\SQLIO.msi /quiet

It looks like it works. You see msiexec flash up into taskmanager but it does not actually install anything. Eventually you go online and find out that you need to pass it to msiexec.exe as an argument with other flags.

msiexec.exe /I .\SQLIO.msi /quiet 

We are starring at the first common problem that can cause a lot of headache. This command is actually throwing an error but the /quiet flag is suppressing it. The message would basically say that it could not find the specified MSI file. 我们缺少的只是MSI的完整路径。

msiexec.exe /I c:\installers\SQLIO.msi /quiet

The next common issue that you run into is needing to wait for the installer to finish. Executing msiexec directly starts the installer but returns control back to the Powershell Script. The way I like to solve this one is with Start-Process -Wait. It will wait until the process finishes before it lets your script continue. The second thing that Start-Process does is ensure that your parameters are processed correctly.

Start-Process msiexec.exe -Wait -ArgumentList '/I C:\installers\SQLIO.msi /quiet'

With that said, any time you are struggling with command line arguments for an executable, use Start-Process -ArgumentList.

这是一个完整的示例,即我在我的脚本中重用以og体育MSI文件。我经常使用这一点,我在自己的函数中包装。

$DataStamp = get-date -Format yyyyMMddTHHmmss
$logFile = '{0}-{1}.log' -f $file.fullname,$DataStamp
$MSIArguments = @(
    "/i"
    ('"{0}"' -f $file.fullname)
    "/qn"
    "/norestart"
    "/L*v"
    $logFile
)
Start-Process "msiexec.exe" -ArgumentList $MSIArguments -Wait -NoNewWindow 

它不仅做了静默og体育,它还捕获了og体育的详细日志。

既然你知道如何默默地执行MSI,下一步是在远程系统上运行该步骤。看到我的帖子 og体育远程软件 关于如何接近。