21

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

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

7 回答 7

20

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

& <path>\filename.msi

或者

Start-Process <path>\filename.msi

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

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

于 2013-07-24T07:08:13.253 回答
20

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

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

我收到了错误:

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

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

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

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

于 2018-05-14T23:11:09.740 回答
7

您可以使用:

msiexec /i "c:\package.msi"

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

于 2013-07-24T08:02:09.597 回答
6
#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,但最终将这个工作脚本拼凑在一起。它工作得很好!以为我会在这里发布希望其他人可以受益。它提取计算机列表,将文件复制到本地计算机并运行它。:) 派对!

于 2013-11-20T18:43:51.257 回答
2

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

foreach($_msiFiles in 
($_msiFiles = Get-ChildItem $_Source -Recurse | Where{$_.Extension -eq ".msi"} |
 Where-Object {!($_.psiscontainter)} | Select-Object -ExpandProperty FullName)) 
{
    msiexec /i $_msiFiles /passive
}
于 2015-02-16T03:11:43.497 回答
1
#$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"

}
于 2014-05-22T11:44:59.933 回答
0

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

install-package .\file.msi

否则,启动过程并等待:

start -wait file.msi ALLUSERS=1,INSTALLDIR=C:\FILE
于 2020-08-25T19:21:33.300 回答