【问题标题】:Install msi using Start-Process with /q switch?使用带有 /q 开关的 Start-Process 安装 msi?
【发布时间】:2017-09-06 06:38:40
【问题描述】:

我想安装一个带有/q 开关的微星,我上网查了一下,示例中没有/q 开关,并且一直出现错误。

我需要类似的东西:

$WorkingDirectory = (Split-Path $myinvocation.mycommand.path -Parent)

Start-Process -FilePath msiexec /i "$WorkingDirectory\LAPS.x64.msi" -ArgumentList /q

【问题讨论】:

    标签: powershell


    【解决方案1】:

    不要打扰Start-Process。使用call operator:

    & msiexec.exe /i "$WorkingDirectory\LAPS.x64.msi" /q
    

    【讨论】:

      【解决方案2】:

      将整个命令放在括号中

      示例(Python msi):

      Start-Process msiexec.exe -Wait -ArgumentList "/I $($LocalPython.FullName) /passive ALLUSERS=1 ADDLOCAL=Extensions" 
      

      /passive 替换为/q

      【讨论】:

        【解决方案3】:

        并非所有安装程序都相同。要查找适用于您的 .msi 的安装程序开关,请使用:

        .\LAPS.x64.msi /?
        .\LAPS.x64.msi -?
        

        我还将msi 路径存储在一个变量中,并使用ArrayList 作为参数,这样的事情在我的脚本中对我有用:

        # Path to .msi
        $msiPath= 'C:\LAPS.x64.msi'
        
        # Define arguments
        [System.Collections.ArrayList]$arguments = 
        @("/i `"$msiPath`"",
        "/quiet")
        
        # Start installation
        Start-Process -FilePath msiexec.exe -ArgumentList "$arguments" -Wait -NoNewWindow
        

        【讨论】:

          【解决方案4】:
          $path="C:\Dat\install.msi"
          $parameters="/q"
          
          $packageinstall=(split-path $path -leaf) + ' ' + $parameters 
          write-host $packageinstall
          $computers = get-content c:\com.txt
          
          $computers | where{test-connection $_ -quiet -count 1} | ForEach-Object {
          
              copy-item $path "\\$_\c$\windows\temp" -Force -Recurse 
              $newProc=([WMICLASS]"\\$_\root\cimv2:win32_Process").Create("C:\windows\temp\$packageinstall")
          
              If ($newProc.ReturnValue -eq 0) {
                  Write-Host $_ $newProc.ProcessId
              } else {
                  write-host $_ Process create failed with $newProc.ReturnValue
              }
          }
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2019-07-26
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多