我对PowerShell非常陌生,理解起来有些困难。
我想在PowerShell脚本中安装.MSI
。
可以请解释我如何做到这一点或为我提供初学者级别的教程。如何使用PowerShell安装.MSI
$wiObject = New-Object -ComObject WindowsInstaller.Installer
?????
我对PowerShell非常陌生,理解起来有些困难。
我想在PowerShell脚本中安装.MSI
。
可以请解释我如何做到这一点或为我提供初学者级别的教程。如何使用PowerShell安装.MSI
$wiObject = New-Object -ComObject WindowsInstaller.Installer
?????
为什么会这么喜欢它?只需调用.msi文件:
或
Start-Process <path>\filename.msi
编辑:开始处理的全部列表参数
您可以使用:
msiexec /i "c:\package.msi"
您还可以添加更多可选参数。有一些常见的msi参数和参数是您的安装程序特有的。对于常见参数,请致电msiexec
@ Adi的答案中的<path>
部分可能会让一个完全陌生于PowerShell或其他命令shell的人感到困惑。
使用windows GUI查找路径的值,右键单击.msi文件,选择'属性',然后选择'细节'。在“文件夹路径”下,您将看到需要写入的内容。
所以你的命令看起来像(例如)
& C:\Users\YourName\YourDirectory\filename.msi
这是有目共睹的谁使用StackOverflow的大多数人,而是一个真正的新手可以很容易误入歧途。
#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,但终于拼凑起了这个工作脚本。它工作得很好!以为我会在这里发布希望其他人可以受益。它提取计算机列表,将文件复制到本地计算机并运行。 :) 派对!
#$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"
}
你必须给你的答案一些意见 – ohlmar
一些考验和磨难之后,我能找到的所有的.msi文件在给定的目录,并安装它们。
foreach($_msiFiles in
($_msiFiles = Get-ChildItem $_Source -Recurse | Where{$_.Extension -eq ".msi"} |
Where-Object {!($_.psiscontainter)} | Select-Object -ExpandProperty FullName))
{
msiexec /i $_msiFiles /passive
}
你可以简单地添加开关和其他参数呢? – Brettski