Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用PowerShell安装.MSI_Powershell_Windows Installer - Fatal编程技术网

如何使用PowerShell安装.MSI

如何使用PowerShell安装.MSI,powershell,windows-installer,Powershell,Windows Installer,我对PowerShell非常陌生,理解起来有些困难。 我想在PowerShell脚本中安装.MSI。 请给我解释一下怎么做,或者给我提供初级教程 $wiObject=新对象-ComObject WindowsInstaller.Installer ????? 为什么对它如此着迷?只需调用.msi文件: &\filename.msi 或 启动进程\filename.msi 编辑:启动过程参数的完整列表 您可以使用: msiexec /i "c:\package.msi" 您还可以添加更多可选

我对PowerShell非常陌生,理解起来有些困难。
我想在PowerShell脚本中安装
.MSI

请给我解释一下怎么做,或者给我提供初级教程

$wiObject=新对象-ComObject WindowsInstaller.Installer
?????

为什么对它如此着迷?只需调用.msi文件:

&\filename.msi

启动进程\filename.msi
编辑:启动过程参数的完整列表

您可以使用:

msiexec /i "c:\package.msi"
您还可以添加更多可选参数。有常见的msi参数和特定于安装程序的参数。对于常见参数,只需调用
msiexec

#变量即可
$computername=获取内容'M:\Applications\Powershell\comp list\Test.txt'
$sourcefile=“\\server\Apps\LanSchool 7.7\Windows\Student.msi”
#本节将安装软件
foreach($computername中的计算机)
{
$destinationFolder=“\\$computer\C$\download\LanSchool”
#此分区将$sourcefile复制到$destinationfolder。如果该文件夹不存在,它将创建该文件夹。
if(!(测试路径-路径$destinationFolder))
{
新项目$destinationFolder-类型目录
}
复制项目-路径$sourcefile-目标$destinationFolder
调用命令-ComputerName$computer-ScriptBlock{&cmd/c“msiexec.exe/ic:\download\LanSchool\Student.msi”/qn ADVANCED_OPTIONS=1 CHANNEL=100}
}
我自己到处寻找这个,找到了Zlich,但最终拼凑出了这个工作脚本。它工作得很好!我想我会在这里发布,希望其他人能从中受益。它拉入计算机列表,将文件复制到本地计算机并运行它。:)开派对

#$computerList=“服务器名称”
#$regVar=“包的名称”
#$packageName=“打包名称”
$computerList=$args[0]
$regVar=$args[1]
$packageName=$args[2]
foreach($computerList中的计算机)
{
写入主机“连接到$computer…”
调用命令-ComputerName$computer-Authentication Kerberos-ScriptBlock{
param(
$computer,
$regVar,
$packageName
)
写入主机“已连接到$computer”
if([IntPtr]::大小-等式4)
{
$registryLocation=Get ChildItem“HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\”
写入主机“连接到32位体系结构”
}
其他的
{
$registryLocation=Get ChildItem“HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\”
写入主机“连接到64位体系结构”
}
写入主机“查找以前版本的`enter code here`$regVar….”
foreach($registryItem in$registryLocation)
{
if((Get-itemproperty$registryItem.PSPath).DisplayName-match$regVar)
{
写入主机“Found$regVar”(GetItemProperty$registryItem.PSPath)
$UninstallString=(获取itemproperty$registryItem.PSPath)。UninstallString
$match=[RegEx]::match($uninstallString,“{.*?}”)
$args=“/x$($match.Value)/qb”
写入主机“卸载$regVar…”
[diagnostics.process]::start(“msiexec”,$args.WaitForExit()
写入主机“卸载的$regVar”
}
}
$path=“\\$computer\Msi\$packageName”
写入主机“安装$path…”
$args=“/i$path/qb”
[diagnostics.process]::start(“msiexec”,$args.WaitForExit()
写入主机“已安装的$path”
}-ArgumentList$computer、$regVar、$packageName
写入主机“部署完成”
}

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

foreach($\msu)中的文件
($_msiFiles=Get ChildItem$_Source-Recurse |其中{$_.Extension-eq.msi}|
其中,对象{!($u.psicontainer)}选择对象-ExpandProperty全名)
{
msiexec/i$\msiu文件/被动
}

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

Start-Process $webDeployInstallerFilePath -ArgumentList '/quiet' -Wait
我得到了一个错误:

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

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

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

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

在powershell 5.1中,您可以实际使用安装包,但它不能接受额外的msi参数

install-package .\file.msi
否则,启动进程并等待:

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

你必须给你的回答提供一些意见,你可以简单地添加开关和其他参数,你也可以做
-ArgumentList'/quiet/passive
/passive
删除将仅使用
/quiet