【问题标题】:How to install .MSI using PowerShell如何使用 PowerShell 安装 .MSI
【发布时间】:2013-07-23 10:24:40
【问题描述】:

我对 PowerShell 非常陌生,理解起来有些困难。
我想在 PowerShell 脚本中安装 .MSI
可以请解释我如何做到这一点或为我提供初学者级别的教程。

$wiObject = New-Object -ComObject WindowsInstaller.Installer
?????

【问题讨论】:

    标签: powershell windows-installer


    【解决方案1】:

    为什么对它如此感兴趣?只需调用 .msi 文件:

    & <path>\filename.msi
    

    Start-Process <path>\filename.msi
    

    编辑:启动过程参数的完整列表

    https://ss64.com/ps/start-process.html

    【讨论】:

    • 而你可以简单地在其中添加开关和其他参数?
    【解决方案2】:

    当尝试使用此命令通过 PowerShell 静默安装 MSI 时:

    Start-Process $webDeployInstallerFilePath -ArgumentList '/quiet' -Wait
    

    我收到了错误:

    指定的可执行文件不是此操作系统平台的有效应用程序。

    我改为使用msiexec.exe 使用此命令执行 MSI,它按预期工作:

    $arguments = "/i `"$webDeployInstallerFilePath`" /quiet"
    Start-Process msiexec.exe -ArgumentList $arguments -Wait
    

    希望其他人觉得这很有用。

    【讨论】:

    • 你也可以-ArgumentList '/quiet /passive/passive 删除任何将仅以 /quiet 显示的 UI
    【解决方案3】:

    你可以使用:

    msiexec /i "c:\package.msi"
    

    您还可以添加更多可选参数。有一些常见的 msi 参数和特定于您的安装程序的参数。常用参数只需调用msiexec

    【讨论】:

      【解决方案4】:
      #Variables
      $computername = Get-Content 'M:\Applications\Powershell\comp list\Test.txt'
      $sourcefile = "\\server\Apps\LanSchool 7.7\Windows\Student.msi"
      #This section will install the software 
      foreach ($computer in $computername) 
      {
          $destinationFolder = "\\$computer\C$\download\LanSchool"
          #This section will copy the $sourcefile to the $destinationfolder. If the Folder does not exist it will create it.
          if (!(Test-Path -path $destinationFolder))
          {
              New-Item $destinationFolder -Type Directory
          }
          Copy-Item -Path $sourcefile -Destination $destinationFolder
          Invoke-Command -ComputerName $computer -ScriptBlock { & cmd /c "msiexec.exe /i c:\download\LanSchool\Student.msi" /qn ADVANCED_OPTIONS=1 CHANNEL=100}
      }
      

      我自己搜索了所有内容并想出了 zilch,但最终将这个工作脚本拼凑在一起。它工作得很好!以为我会在这里发布希望其他人可以受益。它提取计算机列表,将文件复制到本地计算机并运行它。 :) 开派对!

      【讨论】:

        【解决方案5】:

        经过一些试验和磨难,我能够在给定目录中找到所有 .msi 文件并安装它们。

        foreach($_msiFiles in 
        ($_msiFiles = Get-ChildItem $_Source -Recurse | Where{$_.Extension -eq ".msi"} |
         Where-Object {!($_.psiscontainter)} | Select-Object -ExpandProperty FullName)) 
        {
            msiexec /i $_msiFiles /passive
        }
        

        【讨论】:

          【解决方案6】:
          #$computerList = "Server Name"
          #$regVar = "Name of the package "
          #$packageName = "Packe name "
          $computerList = $args[0]
          $regVar = $args[1]
          $packageName = $args[2]
          foreach ($computer in $computerList)
          {
              Write-Host "Connecting to $computer...."
              Invoke-Command -ComputerName $computer -Authentication Kerberos -ScriptBlock {
              param(
                  $computer,
                  $regVar,
                  $packageName
                  )
          
                  Write-Host "Connected to $computer"
                  if ([IntPtr]::Size -eq 4)
                  {
                      $registryLocation = Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\"
                      Write-Host "Connected to 32bit Architecture"
                  }
                  else
                  {
                      $registryLocation = Get-ChildItem "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\"
                      Write-Host "Connected to 64bit Architecture"
                  }
                  Write-Host "Finding previous version of `enter code here`$regVar...."
                  foreach ($registryItem in $registryLocation)
                  {
                      if((Get-itemproperty $registryItem.PSPath).DisplayName -match $regVar)
                      {
                          Write-Host "Found $regVar" (Get-itemproperty $registryItem.PSPath).DisplayName
                          $UninstallString = (Get-itemproperty $registryItem.PSPath).UninstallString
                              $match = [RegEx]::Match($uninstallString, "{.*?}")
                              $args = "/x $($match.Value) /qb"
                              Write-Host "Uninstalling $regVar...."
                              [diagnostics.process]::start("msiexec", $args).WaitForExit() 
                              Write-Host "Uninstalled $regVar"
                      }
                  }
          
                  $path = "\\$computer\Msi\$packageName"
                  Write-Host "Installaing $path...."
                  $args = " /i $path /qb"
                  [diagnostics.process]::start("msiexec", $args).WaitForExit()
                  Write-Host "Installed $path"
              } -ArgumentList $computer, $regVar, $packageName
          Write-Host "Deployment Complete"
          
          }
          

          【讨论】:

          • 你必须给你的答案一些 cmets
          【解决方案7】:

          在 powershell 5.1 中,您实际上可以使用 install-package,但它不能接受额外的 msi 参数。

          install-package .\file.msi
          

          否则启动进程并等待:

          start -wait file.msi ALLUSERS=1,INSTALLDIR=C:\FILE
          

          【讨论】:

            猜你喜欢
            • 2015-07-06
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2014-02-16
            • 1970-01-01
            • 2016-09-21
            • 2021-07-05
            • 1970-01-01
            相关资源
            最近更新 更多